| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205 | 
							- using System;
 
- using System.Collections.Generic;
 
- using System.Data;
 
- using System.Linq;
 
- using System.Text;
 
- using System.Threading.Tasks;
 
- using cuidian.Sql;
 
- using WangToTempDb;
 
- using cuidian.OpenApi;
 
- using cuidian.OpenApi.Api;
 
- using cuidian.OpenApi.Model;
 
- using cuidian.OpenApi.Utils;
 
- using cuidian.Common;
 
- namespace YlInit
 
- {
 
-     public class Stock : IProcess
 
-     {
 
-         StringBuilder __sb = new StringBuilder();
 
-         public void Process()
 
-         {
 
-             __WangToTemp();
 
-             __TempDbToUfida();
 
-         }
 
-         private void __WangToTemp()
 
-         {
 
-             if (__Step0()) return;
 
-             __Step1();
 
-             __Step2();
 
-         }
 
-         /// <summary>
 
-         /// 判断是否有记录
 
-         /// </summary>
 
-         /// <returns></returns>
 
-         private bool __Step0()
 
-         {
 
-             string sql = "select count(1) from wtu..stock";
 
-             int cnt = (int)DbUtils.ExecuteScalar(sql, ConnectionUtils.Instance.GetConnection());
 
-             return cnt > 0;
 
-         }
 
-         /// <summary>
 
-         /// 第一步,用仓库去抓库存
 
-         /// </summary>
 
-         private void __Step1()
 
-         {
 
-             string sql = "select cwhcode from warehouse";
 
-             DataTable dt = DbUtils.Fill(sql, ConnectionUtils.Instance.GetConnection());
 
-           
 
-             foreach (DataRow dr in dt.Rows)
 
-             {
 
-                 StockUpLoad up = new StockUpLoad();
 
-                 Dictionary<string, string> args = new Dictionary<string, string>();
 
-                 args["warehouse_no"] = dr["cwhcode"].ToString();
 
-                 args["start_time"] = "2019-9-1 00:00:00";
 
-                 args["end_time"] = Convert.ToDateTime(DateTime.Now.AddMinutes(-10).ToString("yyyy-MM-dd HH:mm:ss")).ToString();
 
-                 up.UpLoad(args);
 
-             }
 
-         }
 
-         /// <summary>
 
-         /// 用存货去找遗漏的资料
 
-         /// </summary>
 
-         private void __Step2()
 
-         {
 
-             string sql = "select cinvcode from inventory where cinvcode not in (select distinct cinvcode from wtu..stock)";
 
-             DataTable dt = DbUtils.Fill(sql, ConnectionUtils.Instance.GetConnection());
 
-             foreach (DataRow item in dt.Rows)
 
-             {
 
-                 StockUpLoad up = new StockUpLoad();
 
-                 Dictionary<string, string> args = new Dictionary<string, string>();
 
-                 args["spec_no"] = item["cinvcode"].ToString();
 
-                 up.UpLoad(args);
 
-             }
 
-         }
 
-         private void __TempDbToUfida()
 
-         {
 
-             string sql = "select distinct cwhcode from stock ORDER by cwhcode";
 
-             DataTable dt = DbUtils.Fill(sql, ConnectionUtils.Instance.GetConnection("TempDB"));
 
-             foreach (DataRow dr in dt.Rows)
 
-             {
 
-                 __GetStock(dr["cwhcode"].ToString());
 
-             }
 
-         }
 
-         private void __GetStock(string cwhcode)
 
-         {
 
-             string sql = "select * from stock where cwhcode='" + cwhcode + "'";             
 
-             DataTable dt = DbUtils.Fill(sql, ConnectionUtils.Instance.GetConnection("TempDB"));
 
-             List<Entry> entrys = new List<Entry>();
 
-             int i = 0;
 
-             List<int> ids = new List<int>();
 
-             DataRow tmp = null;
 
-             if (dt.Rows.Count == 0) return;
 
-             foreach (DataRow item in dt.Rows)
 
-             {
 
-                 ids.Add(Convert.ToInt32(item["sysid"]));
 
-                 tmp = item;
 
-                 if (i == 300)
 
-                 {
 
-                     __Add(entrys, item,ids);
 
-                     i = 0;
 
-                     entrys.Clear();
 
-                     ids.Clear();
 
-                 }
 
-                 else
 
-                 {
 
-                     Entry detail = __GetDetail(item);
 
-                     detail.rowno = (i + 1).ToString();
 
-                     entrys.Add(detail);
 
-                     i++;
 
-                 }
 
-             }
 
-             if (entrys.Count > 0)
 
-             {
 
-                 __Add(entrys, tmp, ids);
 
-             }
 
-             if (__sb.Length > 0) throw new Exception(__sb.ToString());
 
-         }
 
-         /// <summary>
 
-         /// 删除成功记录
 
-         /// </summary>
 
-         private void __Delete(List<int> ids)
 
-         {            
 
-             string sql = "delete from stock where sysid in (" + ListUtils.ToString(ids, ",") + ")";
 
-             DbUtils.ExecuteNonQuery(sql, ConnectionUtils.Instance.GetConnection("TempDB"));
 
-         }
 
-         private void __Add(List<Entry> entrys,DataRow dr,List<int> ids)
 
-         {
 
-             Otherin v = __GetHead(dr);
 
-             Entry[] details = new Entry[entrys.Count];
 
-             entrys.CopyTo(details);
 
-             v.entry = details;
 
-             OtherinRoot vr = new OtherinRoot();
 
-             vr.otherin = v;
 
-             OtherinApi api = new OtherinApi();
 
-             BusinessObject result = api.Add(JsonUtils.GetJsonString(vr));
 
-             if (result.IsError == false)
 
-             {
 
-                 api.Audit(result.Id);
 
-                 __Delete(ids);
 
-             }
 
-             else
 
-             {
 
-                 __sb.AppendLine(result.ErrMsg);
 
-             }
 
-             
 
-         }
 
-         private Otherin __GetHead(DataRow item)
 
-         {
 
-             Otherin v = new Otherin();
 
-             v.date = DateTime.Now.ToString("yyyy-MM-dd");
 
-             v.warehousecode = item["cwhcode"].ToString();
 
-             v.define5 = "1";
 
-             v.define1 = "来源旺店通";
 
-             return v;
 
-         }
 
-         private Entry __GetDetail(DataRow dr)
 
-         {
 
-             Entry rtn = new Entry();
 
-             rtn.inventorycode = dr["cinvcode"].ToString();
 
-             rtn.quantity = dr["qty"].ToString();
 
-             decimal price = Convert.ToDecimal(dr["price"]);
 
-             if (price > 0)
 
-             {
 
-                 rtn.price = price.ToString();
 
-                 rtn.cost = Math.Round( Convert.ToDecimal(dr["qty"]) * price,2).ToString();
 
-             }
 
-            
 
-             
 
-             return rtn;
 
-         }
 
-     }
 
-         
 
- }
 
 
  |