You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
DS7/DSWeb.Interface/HSZQY.cs

355 lines
12 KiB
C#

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

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
}
}