|
|
|
|
|
using System;
|
|
|
using System.Collections.Generic;
|
|
|
using System.IO;
|
|
|
using System.Text;
|
|
|
using Newtonsoft.Json;
|
|
|
|
|
|
using HcUtility.Comm;
|
|
|
using DSWeb.Common.DB;
|
|
|
using System.Linq;
|
|
|
using DSWeb.Common.Helper;
|
|
|
|
|
|
namespace DSWeb.Interface
|
|
|
{
|
|
|
class HSZQY
|
|
|
{
|
|
|
|
|
|
#region 红柿子-青银 接收费用信息接口
|
|
|
|
|
|
public class HSZQY_FEEInfo
|
|
|
{
|
|
|
public string ac { get; set; }
|
|
|
public string uid { get; set; }
|
|
|
public string skey { get; set; }
|
|
|
public string optype { get; set; }
|
|
|
|
|
|
public List<HSZQY_mdata> mdata { get; set; }
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
/// 判断数据是否合法
|
|
|
/// </summary>
|
|
|
/// <returns></returns>
|
|
|
public DBResult InfoRight() {
|
|
|
var result = new DBResult(true, "");
|
|
|
|
|
|
var error = "";
|
|
|
|
|
|
if (uid == "") return new DBResult(false, "【uid 用户名】不能为空");
|
|
|
|
|
|
CommonDataContext cdc = new CommonDataContext();
|
|
|
|
|
|
//foreach (var head in mdata) {
|
|
|
// if (head.MBLNO == "") return new DBResult(false, "【mdata中的MBLNO 提单号】不能为空");
|
|
|
|
|
|
// //判断客户名在结算对象表中是否存在
|
|
|
|
|
|
// var infoclient = cdc.info_client.Where(x => x.SHORTNAME == head.CUSTOMERNAME || x.DESCRIPTION == head.CUSTOMERNAME).ToList();
|
|
|
|
|
|
// if (infoclient == null || infoclient.Count == 0) {
|
|
|
// error += "【customer用户名】[" + head.CUSTOMERNAME + "]在财务系统的往来单位中不存在;";
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
|
|
//}
|
|
|
foreach (var head in mdata)
|
|
|
{
|
|
|
foreach (var fee in head.feedata)
|
|
|
{
|
|
|
|
|
|
|
|
|
// //判断费用名称是否存在
|
|
|
|
|
|
// var codefee = cdc.code_fee.Where(x => x.NAME == fee.FEENAME).ToList();
|
|
|
|
|
|
// if (codefee == null || codefee.Count == 0) {
|
|
|
// error += "【FEENAME费用名称】[" + fee.FEENAME + "]在财务系统的费用代码表中不存在;";
|
|
|
// }
|
|
|
//如果feetype不为1或2 返回错误
|
|
|
|
|
|
if (fee.FEETYPE != 1 && fee.FEETYPE != 2)
|
|
|
{
|
|
|
error += "【FEETYPE收付方向】必须是1(应收)或2(应付);";
|
|
|
}
|
|
|
if (fee.UNITPRICE == null || fee.UNITPRICE == null || fee.UNITPRICE == null || fee.UNITPRICE == null || fee.UNITPRICE == null || fee.UNITPRICE == null)
|
|
|
{
|
|
|
error += "所有数字类信息都不能为空;";
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (error != "") {
|
|
|
result.SetErrorInfo(error);
|
|
|
}
|
|
|
|
|
|
return result;
|
|
|
}
|
|
|
|
|
|
|
|
|
private CommonDataContext cdc_b = new CommonDataContext();
|
|
|
|
|
|
private op_other_md getOPOTHER(HSZQY_mdata head) {
|
|
|
|
|
|
var result = new op_other_md();
|
|
|
|
|
|
result.BSNO = Guid.NewGuid().ToString();
|
|
|
|
|
|
result.BSSOURCE = head.GID;
|
|
|
|
|
|
result.OPLB = "op_other";
|
|
|
result.OPLBNAME = head.OPLBNAME;
|
|
|
|
|
|
result.BSSTATUS = false;
|
|
|
result.FEESTATUS = false;
|
|
|
|
|
|
result.MBLNO = head.MBLNO;
|
|
|
result.orderno = head.ORDERNO;
|
|
|
|
|
|
result.ISVOU = false;
|
|
|
|
|
|
result.BSDATE = Convert.ToDateTime( DateTime.Now.ToString("yyyy-MM-dd"));
|
|
|
|
|
|
result.ACCDATE = DateTime.Now.ToString("yyyy-MM");
|
|
|
result.ETD = Convert.ToDateTime(DateTime.Now.ToString("yyyy-MM-dd"));
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var infoclient = cdc_b.info_client.Where(x => x.SHORTNAME == head.CUSTOMERNAME || x.DESCRIPTION == head.CUSTOMERNAME).ToList();
|
|
|
|
|
|
if (infoclient == null || infoclient.Count == 0)
|
|
|
{
|
|
|
result.CUSTOMERNAME = "";
|
|
|
result.REMARK = "未识别客户[" + head.CUSTOMERNAME + "]";
|
|
|
}
|
|
|
else {
|
|
|
|
|
|
result.CUSTOMERNAME = infoclient[0].NAME;
|
|
|
}
|
|
|
return result;
|
|
|
}
|
|
|
|
|
|
private List<op_other_md> getOPOTHERList() {
|
|
|
var newlist = new List<op_other_md>();
|
|
|
foreach (var head in mdata) {
|
|
|
|
|
|
var newrec = getOPOTHER(head);
|
|
|
|
|
|
if (!业务已存在(newrec)) {
|
|
|
newlist.Add(newrec);
|
|
|
}
|
|
|
}
|
|
|
return newlist;
|
|
|
}
|
|
|
|
|
|
private bool 业务已存在(op_other_md opother) {
|
|
|
var opotherlist = cdc_b.op_other.Where(x => x.BSNO == opother.BSNO).ToList();
|
|
|
|
|
|
if (opotherlist == null || opotherlist.Count == 0) {
|
|
|
return false;
|
|
|
}
|
|
|
return true;
|
|
|
}
|
|
|
private bool 费用已存在(ch_fee_md chfee)
|
|
|
{
|
|
|
var opotherlist = cdc_b.ch_fee.Where(x => x.GID == chfee.GID).ToList();
|
|
|
|
|
|
if (opotherlist == null || opotherlist.Count == 0)
|
|
|
{
|
|
|
return false;
|
|
|
}
|
|
|
return true;
|
|
|
}
|
|
|
|
|
|
private ch_fee_md getchfee(HSZQY_feedata feedata,string BSNO) {
|
|
|
var result = ModelHelper.getchfeeHelper();
|
|
|
result.GID = feedata.FEEID;
|
|
|
result.BSNO = BSNO;
|
|
|
try {
|
|
|
result.ENTERDATE = Convert.ToDateTime( feedata.ENTERDATE);
|
|
|
}
|
|
|
catch (Exception e) {
|
|
|
result.ENTERDATE = DateTime.Now;
|
|
|
}
|
|
|
|
|
|
var infoclient = cdc_b.info_client.Where(x => x.SHORTNAME == feedata.CUSTOMERNAME || x.DESCRIPTION == feedata.CUSTOMERNAME).ToList();
|
|
|
|
|
|
if (infoclient == null || infoclient.Count == 0)
|
|
|
{
|
|
|
result.CUSTOMERNAME = "";
|
|
|
result.REMARK = "未识别客户[" + feedata.CUSTOMERNAME + "];";
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
|
|
|
result.CUSTOMERNAME = infoclient[0].NAME;
|
|
|
}
|
|
|
|
|
|
var feename = cdc_b.code_fee.Where(x => x.NAME == feedata.FEENAME).ToList();
|
|
|
|
|
|
if (feename == null || feename.Count == 0)
|
|
|
{
|
|
|
result.FEENAME = "";
|
|
|
result.REMARK += "未识别费用名称[" + feedata.FEENAME + "];";
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
|
|
|
result.FEENAME = feename[0].NAME;
|
|
|
}
|
|
|
|
|
|
result.FEETYPE = feedata.FEETYPE;
|
|
|
result.UNITPRICE = feedata.UNITPRICE;
|
|
|
result.QUANTITY = feedata.QUANTITY;
|
|
|
result.NOTAXAMOUNT = feedata.NOTAXAMOUNT;
|
|
|
result.TAXRATE = feedata.TAXRATE;
|
|
|
result.TAX = feedata.TAX;
|
|
|
result.AMOUNT = feedata.AMOUNT;
|
|
|
|
|
|
return result;
|
|
|
|
|
|
}
|
|
|
private List<ch_fee_md> getFeeList(List<op_other_md> 业务表List) {
|
|
|
var result = new List<ch_fee_md>();
|
|
|
|
|
|
foreach (var head in mdata)
|
|
|
{
|
|
|
foreach (var item in head.feedata)
|
|
|
{
|
|
|
var _head_other = 业务表List.First(x => x.BSSOURCE == head.GID);
|
|
|
|
|
|
var neefee = getchfee(item, _head_other.BSNO);
|
|
|
|
|
|
if (!费用已存在(neefee))
|
|
|
{
|
|
|
result.Add(neefee);
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
return result;
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
|
/// 向数据库中插入数据
|
|
|
/// </summary>
|
|
|
/// <returns></returns>
|
|
|
public DBResult DoSave(List<string> BSNO) {
|
|
|
var result = new DBResult(true, "");
|
|
|
|
|
|
//1 获取待插入的业务列表
|
|
|
var 业务表 = getOPOTHERList();
|
|
|
var _count = 0;
|
|
|
foreach (var item in 业务表) {
|
|
|
item.CUSTNO = BSNO[_count];
|
|
|
_count++;
|
|
|
}
|
|
|
|
|
|
//2 获取待插入的费用列表
|
|
|
var 费用表 = getFeeList(业务表);
|
|
|
|
|
|
//20211111 增加判断 如一个业务没有对应费用 则将其去除
|
|
|
if (费用表 != null && 费用表.Count > 0)
|
|
|
{
|
|
|
业务表 = 业务表.Where(x => 费用表.Select(s => s.BSNO).Contains(x.BSNO)).ToList();
|
|
|
}
|
|
|
else {
|
|
|
业务表.Clear();
|
|
|
}
|
|
|
|
|
|
//3 如上述二列表有一个不为空 就执行插入 并返回插入结果
|
|
|
//如这俩列表为空 返回错误
|
|
|
if (业务表.Count > 0 || 费用表.Count > 0)
|
|
|
{
|
|
|
|
|
|
var cdc = new CommonDataContext();
|
|
|
if(业务表.Count > 0)
|
|
|
cdc.op_other.AddRange(业务表);
|
|
|
if (费用表.Count > 0)
|
|
|
cdc.ch_fee.AddRange(费用表);
|
|
|
cdc.SaveChanges();
|
|
|
result.OK($"添加成功!记录了{业务表.Count()}条业务,{费用表.Count()}条费用");
|
|
|
}
|
|
|
else {
|
|
|
result.SetErrorInfo("没有需要保存的信息");
|
|
|
}
|
|
|
|
|
|
return result;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
public class HSZQY_mdata
|
|
|
{
|
|
|
public string MBLNO { get; set; }
|
|
|
/// <summary>
|
|
|
/// 20220104 客户要求增加记录费用从属于哪个仓库
|
|
|
/// 而ch_fee表并没有易用的字段可以用来记录新的维度
|
|
|
/// 故在主表增加记录 将仓库名称记录在ORDERNO订舱编号 上
|
|
|
/// </summary>
|
|
|
public string ORDERNO { get; set; }
|
|
|
public string CUSTOMERNAME { get; set; }
|
|
|
public string OPLBNAME { get; set; }
|
|
|
public string GID { get; set; }
|
|
|
|
|
|
public List<HSZQY_feedata> feedata { get; set; }
|
|
|
|
|
|
|
|
|
}
|
|
|
public class HSZQY_feedata
|
|
|
{
|
|
|
public string FEEID { get; set; }
|
|
|
public string ENTERDATE { get; set; }
|
|
|
public string FEENAME { get; set; }
|
|
|
public string CUSTOMERNAME { get; set; }
|
|
|
public int? FEETYPE { get; set; }
|
|
|
public decimal? UNITPRICE { get; set; }
|
|
|
public decimal? QUANTITY { get; set; }
|
|
|
public decimal? NOTAXAMOUNT { get; set; }
|
|
|
public decimal? TAXRATE { get; set; }
|
|
|
public decimal? TAX { get; set; }
|
|
|
public decimal? AMOUNT { get; set; }
|
|
|
}
|
|
|
|
|
|
|
|
|
public static DBResult StockFee(List<string> BSNO,string strJson)
|
|
|
{
|
|
|
var result = new DBResult(false, "");
|
|
|
try
|
|
|
{
|
|
|
|
|
|
|
|
|
|
|
|
var HSZQYInfo = JsonConvert.DeserializeObject<HSZQY_FEEInfo>(strJson.ToString());
|
|
|
|
|
|
//首先判断数据是否合法
|
|
|
//如非法则返回错误
|
|
|
var 数据合法 = HSZQYInfo.InfoRight();
|
|
|
if (!数据合法.Success) return 数据合法;
|
|
|
|
|
|
//然后根据ID判断业务和费用是否存在,如有存在的则返回错误
|
|
|
|
|
|
var 保存结果 = HSZQYInfo.DoSave(BSNO);
|
|
|
|
|
|
return 保存结果;
|
|
|
|
|
|
//保存数据
|
|
|
|
|
|
//result.OK("保存完成");
|
|
|
|
|
|
}
|
|
|
catch (Exception ex)
|
|
|
{
|
|
|
result.SetErrorInfo(ex.Message);
|
|
|
return result;
|
|
|
}
|
|
|
return result;
|
|
|
}
|
|
|
|
|
|
#endregion
|
|
|
}
|
|
|
}
|