Esempio n. 1
0
        /// <summary>
        /// List_ID基础资料批量审核成功后,更新物料的相关信息
        /// </summary>
        /// <param name="ctx"></param>
        /// <param name="infos"></param>
        /// <returns></returns>
        private int UpdateMaterialInfo(Context ctx, IEnumerable <AbsSynchroDataInfo> datas)
        {
            int             count = 0;
            List <ListInfo> infos = null;

            if (datas != null && datas.Count() > 0)
            {
                infos = datas.Select(d => (ListInfo)d).ToList();
            }

            if (infos != null && infos.Count() > 0)
            {
                foreach (var info in infos)
                {
                    if (info != null)
                    {
                        string sql = string.Format(@"/*dialect*/update a set a.F_HS_LISTNAME = '{0}'
                                                                from T_BD_MATERIAL a 
                                                                inner join T_BD_MATERIAL_L b on b.FMATERIALID = a.FMATERIALID and b.FLOCALEID=2052
                                                                inner join T_BD_MATERIALBASE c on c.FMATERIALID = a.FMATERIALID 
                                                                inner join T_BD_MATERIALSALE d on d.FMATERIALID = a.FMATERIALID
                                                                inner join T_BD_MATERIALSTOCK e on e.FMATERIALID = a.FMATERIALID
                                                                inner join T_ORG_ORGANIZATIONS f on a.FUSEORGID=f.FORGID
                                                                left join T_BD_unit_L h on d.FSaleUnitId =h.FUNITID and h.FLOCALEID=2052
											                    inner join HS_T_Brand j on j.FID = a.F_HS_Brand
											                    inner join HS_T_BRAND_L r on r.FID = j.FID
											                    inner join HS_T_BD_LISTID k on k.FID = a.F_HS_ListIDNew
											                    inner join HS_T_BD_LISTID_L l on l.FID = k.FID
											                    inner join T_BAS_ASSISTANTDATAENTRY_L m ON a.F_HS_PRODUCTSTATUS=m.FENTRYID
                                                                inner join T_BAS_ASSISTANTDATAENTRY n ON m.FentryID=n.FentryID
                                                                inner join T_BD_MATERIALGROUP q on q.FID = a.FMaterialGroup  
											                    where a.FNUMBER not like '99.%'
											                    and k.FNUMBER = '{1}'

											            "                                            , SQLUtils.DealQuotes(info.F_HS_ListName), info.F_HS_ListID) + System.Environment.NewLine;
                        sql += string.Format(@"/*dialect*/    update b set b.FName  ='{0}'
                                                                from T_BD_MATERIAL a 
                                                                inner join T_BD_MATERIAL_L b on b.FMATERIALID = a.FMATERIALID and b.FLOCALEID=2052
                                                                inner join T_BD_MATERIALBASE c on c.FMATERIALID = a.FMATERIALID 
                                                                inner join T_BD_MATERIALSALE d on d.FMATERIALID = a.FMATERIALID
                                                                inner join T_BD_MATERIALSTOCK e on e.FMATERIALID = a.FMATERIALID
                                                                inner join T_ORG_ORGANIZATIONS f on a.FUSEORGID=f.FORGID
                                                                left join T_BD_unit_L h on d.FSaleUnitId =h.FUNITID and h.FLOCALEID=2052
											                    inner join HS_T_Brand j on j.FID = a.F_HS_Brand
											                    inner join HS_T_BRAND_L r on r.FID = j.FID
											                    inner join HS_T_BD_LISTID k on k.FID = a.F_HS_ListIDNew
											                    inner join HS_T_BD_LISTID_L l on l.FID = k.FID
											                    inner join T_BAS_ASSISTANTDATAENTRY_L m ON a.F_HS_PRODUCTSTATUS=m.FENTRYID
                                                                inner join T_BAS_ASSISTANTDATAENTRY n ON m.FentryID=n.FentryID
                                                                inner join T_BD_MATERIALGROUP q on q.FID = a.FMaterialGroup  
											                    where a.FNUMBER not like '99.%'
											                    and k.FNUMBER = '{1}'"                                            , SQLUtils.DealQuotes(info.F_HS_ListName), info.F_HS_ListID);

                        count += DBUtils.Execute(ctx, sql);
                    }
                }
            }

            return(count);
        }
Esempio n. 2
0
        public override string GetExecuteUpdateSql(Context ctx, List <AbsSynchroDataInfo> datas)
        {
            string sql     = string.Empty;
            string execSql = string.Empty;
            int    i       = 0;

            try
            {
                if (datas != null && datas.Count > 0)
                {
                    foreach (var data in datas)
                    {
                        if (data != null)
                        {
                            if (data != null)
                            {
                                AbsDataInfo reFund = data as AbsDataInfo;

                                if (reFund != null)
                                {
                                    if (reFund.F_HS_RateToUSA > 0)
                                    {
                                        string billNo = reFund.FBillNo.Contains("_") ? reFund.FBillNo.Split('_')[0] : reFund.FBillNo;


                                        sql += string.Format(@"/*dialect*/ update a set a.F_HS_YNSync ='{0}',a.F_HS_RateToUSA = {1}
                                                                    from T_AR_REFUNDBILL a
                                                                    inner join T_AR_REFUNDBILLENTRY b on a.FID = b.FID
                                                                    inner join T_BD_CUSTOMER c on a.F_HS_B2CCustId = c.FCUSTID
                                                                    inner join T_ORG_ORGANIZATIONS d on a.FSALEORGID = d.FORGID
                                                                    where a.F_HS_YNSync = '{2}'and c.FNumber = '{3}'
                                                                    and a.FBillNo = '{4}'
                                                                    and d.FNUMBER = '{5}'", "1", reFund.F_HS_RateToUSA, "0", reFund.F_HS_B2CCustId, billNo, reFund.FSaleOrgId) + Environment.NewLine;
                                        sql += string.Format(@"/*dialect*/ update a set a.F_HS_RefundTurnUSD = {0},F_HS_BalanceRechargeUSD = {4},F_HS_CreditLineRechargeUSD = {5}
                                                                    from T_AR_REFUNDBILLENTRY a
			                                                        inner join T_AR_REFUNDBILL b on b.FID = a.FID
			                                                        inner join T_ORG_ORGANIZATIONS c on b.FSALEORGID = c.FORGID
			                                                        where b.FBILLNO = '{1}'
			                                                        and c.FNUMBER = '{2}'
			                                                        and a.FENTRYID = {3}"            , reFund.FRealAmountFor_USD, billNo, reFund.FSaleOrgId, reFund.FEntryId
                                                             , reFund.F_HS_BalanceRechargeUSD, reFund.F_HS_CreditLineRechargeUSD) + Environment.NewLine;
                                        sql += string.Format(@"/*dialect*/  update a set a.F_HS_USDBalance = a.F_HS_USDBalance + {0}{3}{4}
                                                                    from T_BD_CUSTOMER a
                                                                    left join T_AR_REFUNDBILL b on a.FCUSTID = b.F_HS_B2CCustId
                                                                    left join T_AR_REFUNDBILLENTRY c on b.FID = c.FID
                                                                    inner join T_ORG_ORGANIZATIONS d on a.FUSEORGID = d.FORGID
                                                                    where a.FNUMBER = '{1}'
                                                                    and d.FNUMBER = '{2}'", reFund.F_HS_BalanceRechargeUSD, reFund.F_HS_B2CCustId, reFund.FSaleOrgId
                                                             , reFund.FSaleOrgId.CompareTo("100.03") == 0 && reFund.FSettleCurrId.CompareTo("CNY") == 0 ? string.Format(@",a.F_HS_CNYBalance = a.F_HS_CNYBalance + {0}"
                                                                                                                                                                        , reFund.FRealAmountFor) : "", string.Format(@",a.F_HS_SurplusCreditUSD = a.F_HS_SurplusCreditUSD + {0}", reFund.F_HS_CreditLineRechargeUSD)) + System.Environment.NewLine;
                                        sql      = "'" + SQLUtils.DealQuotes(sql) + "'";
                                        execSql += string.Format(@"EXEC(" + sql + ")") + Environment.NewLine;
                                        execSql += string.Format(@"declare @balance{2} decimal(10,2)
                                                                   declare @cnybalance{4} decimal(10,2)
                                                                   declare @creditbalance{11} decimal(10,2)
                                                                       set @balance{3} = ( select F_HS_USDBalance from T_BD_CUSTOMER a 
                                                                                           inner join T_ORG_ORGANIZATIONS b on a.FUSEORGID = b.FORGID
                                                                                           where a.FNUMBER = '{0}' and b.FNUMBER = '{1}'
                                                                                         )
                                                                       set @cnybalance{5} = ( select F_HS_CNYBalance from T_BD_CUSTOMER a 
                                                                                              inner join T_ORG_ORGANIZATIONS b on a.FUSEORGID = b.FORGID
                                                                                              where a.FNUMBER = '{6}' and b.FNUMBER = '{7}'
                                                                                            )
                                                                       set @creditbalance{8} = ( select F_HS_SurplusCreditUSD from T_BD_CUSTOMER a 
                                                                                              inner join T_ORG_ORGANIZATIONS b on a.FUSEORGID = b.FORGID
                                                                                              where a.FNUMBER = '{9}' and b.FNUMBER = '{10}'
                                                                                        )
                                                            ", reFund.F_HS_B2CCustId, reFund.FSaleOrgId, i, i, i, i, reFund.F_HS_B2CCustId, reFund.FSaleOrgId, i, reFund.F_HS_B2CCustId, reFund.FSaleOrgId, i) + System.Environment.NewLine;


                                        if (reFund.F_HS_BalanceRechargeUSD > 0)
                                        {
                                            execSql += string.Format(@"/*dialect*/ insert into HS_T_customerBalance(F_HS_TradeType,F_HS_UseOrgId,F_HS_B2CCUSTID,changedAmount,changedType,changedCause
                                                               ,balanceAmount,F_HS_RateToUSA,FSETTLECURRID,changedAmountUSA,balanceAmountUSA,F_HS_CNYBalance,updateTime
                                                               ,updateUser,FBillNo,fentryID,needfreezed,remark) values ('{18}','{15}','{0}',{1},'{2}','{3}',@balance{13}*{17},{4},{5}
                                                               ,{6},@balance{14}, @cnybalance{16},'{7}',{8},'{9}',{10},{11},'{12}') ", SQLUtils.GetCustomerId(ctx, reFund.F_HS_B2CCustId, 1), reFund.F_HS_BalanceRechargeUSD * reFund.F_HS_RateToUSA
                                                                     , reFund.ChangedType, reFund.ChangedCause, reFund.F_HS_RateToUSA, SQLUtils.GetSettleCurrId(ctx, reFund.FSettleCurrId)
                                                                     , reFund.F_HS_BalanceRechargeUSD, DateTime.Now, ctx.UserId, billNo, reFund.FEntryId, reFund.NeedFreezed == false ? 0 : 1, reFund.Remark, i, i
                                                                     , SQLUtils.GetOrgId(ctx, reFund.FSaleOrgId), i, reFund.F_HS_RateToUSA, "余额") + Environment.NewLine;
                                        }

                                        if (reFund.F_HS_CreditLineRechargeUSD > 0)
                                        {
                                            execSql += string.Format(@"/*dialect*/ insert into HS_T_customerBalance(F_HS_TradeType,F_HS_UseOrgId,F_HS_B2CCUSTID,changedAmount,changedType,changedCause
                                                               ,balanceAmount,F_HS_RateToUSA,FSETTLECURRID,changedAmountUSA,balanceAmountUSA,F_HS_CNYBalance,updateTime
                                                               ,updateUser,FBillNo,fentryID,needfreezed,remark) values ('{18}','{15}','{0}',{1},'{2}','{3}',@creditbalance{13}*{17},{4},{5}
                                                               ,{6},@creditbalance{14}, @cnybalance{16},'{7}',{8},'{9}',{10},{11},'{12}') ", SQLUtils.GetCustomerId(ctx, reFund.F_HS_B2CCustId, 1), reFund.F_HS_CreditLineRechargeUSD * reFund.F_HS_RateToUSA
                                                                     , reFund.ChangedType, reFund.ChangedCause, reFund.F_HS_RateToUSA, SQLUtils.GetSettleCurrId(ctx, reFund.FSettleCurrId)
                                                                     , reFund.F_HS_CreditLineRechargeUSD, DateTime.Now, ctx.UserId, billNo, reFund.FEntryId, reFund.NeedFreezed == false ? 0 : 1, reFund.Remark, i, i
                                                                     , SQLUtils.GetOrgId(ctx, reFund.FSaleOrgId), i, reFund.F_HS_RateToUSA, "剩余信用额度") + Environment.NewLine;
                                        }
                                        sql = string.Empty;
                                        i++;
                                    }
                                    else
                                    {
                                        LogUtils.WriteSynchroLog(ctx, this.DataType, "获取【" + reFund.FSettleCurrId + "币别】兑美元的实时汇率失败");
                                    }
                                }
                            }
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                LogUtils.WriteSynchroLog(ctx, this.DataType, ex.Message + System.Environment.NewLine + ex.StackTrace);
            }
            return(execSql);
        }
        public override string GetExecuteUpdateSql(Context ctx, List <AbsSynchroDataInfo> datas)
        {
            string sql = string.Empty;

            string execSql = string.Empty;
            int    i       = 0;

            try
            {
                if (datas != null && datas.Count > 0)
                {
                    foreach (var data in datas)
                    {
                        if (data != null)
                        {
                            AbsDataInfo order = data as AbsDataInfo;

                            if (order != null)
                            {
                                if (order.F_HS_RateToUSA > 0)
                                {
                                    //pending单作废成功
                                    if (order.F_HS_SaleOrderSource.CompareTo("HCWebPendingOder") == 0 && order.FCancelStatus.CompareTo("B") == 0 &&
                                        order.FRealAmountFor > 0 && !order.F_HS_BalanceDeducted)
                                    {
                                        execSql += string.Format(@"/*dialect*/ update a set a.F_HS_BalanceDeducted = '{0}' 
                                                                        from T_SAL_ORDER a 
                                                                        inner join T_BD_CUSTOMER b on a.FCUSTID = b.FCUSTID
                                                                        inner join T_ORG_ORGANIZATIONS c on a.FSALEORGID = c.FORGID
                                                                        where a.FBillNo = '{1}'
                                                                        and c.FNUMBER = '{2}'", "1", order.FBillNo, order.FSaleOrgId) + System.Environment.NewLine;
                                    }
                                    else
                                    {
                                        if (order.F_HS_SaleOrderSource.CompareTo("DropShippingOrder") == 0)
                                        {
                                            sql += string.Format(@"/*dialect*/ update a set a.F_HS_BalanceDeducted = '{0}' ,a.F_HS_BalancePayments = {1},a.F_HS_USDBalancePayments = {2}
                                                                ,a.F_HS_CreditLineUSDPayments = {3},a.F_HS_NeedPayAmount = 0,a.F_HS_PaymentStatus = '3'
                                                                from T_SAL_ORDER a 
                                                                inner join T_BD_CUSTOMER b on a.FCUSTID = b.FCUSTID
                                                                inner join T_ORG_ORGANIZATIONS c on a.FSALEORGID = c.FORGID
                                                                where a.FBillNo = '{4}'
                                                                and b.FNUMBER = '{5}'
                                                                and c.FNUMBER = '{6}'", "1", -order.F_HS_BalanceRecharge, -order.F_HS_BalanceRechargeUSD, -order.F_HS_CreditLineRechargeUSD, order.FBillNo, order.F_HS_B2CCustId, "100.01");

                                            sql += string.Format(@"/*dialect*/  update a set a.F_HS_USDBalance = a.F_HS_USDBalance + {0},a.F_HS_SurplusCreditUSD = F_HS_SurplusCreditUSD + {1}
                                                                from T_BD_CUSTOMER a
                                                                left join T_SAL_ORDER b on a.FCUSTID = b.FCUSTID
                                                                inner join T_ORG_ORGANIZATIONS c on a.FUSEORGID = c.FORGID
                                                                where a.FNUMBER = '{2}'
                                                                and c.FNUMBER = '{3}'", order.F_HS_BalanceRechargeUSD, order.F_HS_CreditLineRechargeUSD, order.F_HS_B2CCustId, "100.01") + System.Environment.NewLine;
                                        }
                                        else
                                        {
                                            sql += string.Format(@"/*dialect*/ update a set a.F_HS_USDBalance = a.F_HS_USDBalance + {0}{3}
                                                                from T_BD_CUSTOMER a
                                                                left join T_SAL_ORDER b on a.FCUSTID = b.FCUSTID
                                                                inner join T_ORG_ORGANIZATIONS c on a.FUSEORGID = c.FORGID
                                                                where a.FNUMBER = '{1}'
                                                                and c.FNUMBER = '{2}'", order.FRealAmountFor_USD, order.F_HS_B2CCustId, order.FSaleOrgId, order.FSaleOrgId.CompareTo("100.03") == 0 && order.FSettleCurrId.CompareTo("CNY") == 0 ? string.Format(@",a.F_HS_CNYBalance = a.F_HS_CNYBalance + {0}", order.FRealAmountFor) : "") + System.Environment.NewLine;


                                            sql += string.Format(@"/*dialect*/ update a set a.F_HS_BalanceDeducted = '{0}' 
                                                                    from T_SAL_ORDER a 
                                                                    inner join T_ORG_ORGANIZATIONS c on a.FSALEORGID = c.FORGID
                                                                    where a.FBillNo = '{1}'
                                                                    and c.FNUMBER = '{2}'", "1", order.FBillNo, order.FSaleOrgId) + System.Environment.NewLine;
                                        }


                                        sql      = "'" + SQLUtils.DealQuotes(sql) + "'";
                                        execSql += string.Format(@"EXEC(" + sql + ")") + System.Environment.NewLine;

                                        if (order.F_HS_SaleOrderSource.CompareTo("DropShippingOrder") == 0)
                                        {
                                            execSql += string.Format(@"declare @balance{0} decimal(10,2)
                                                                       declare @cnybalance{1} decimal(10,2)
                                                                       declare @creditbalance{2} decimal(10,2)
                                                                       set @balance{3} = ( select F_HS_USDBalance from T_BD_CUSTOMER a 
                                                                                           inner join T_ORG_ORGANIZATIONS b on a.FUSEORGID = b.FORGID
                                                                                           where a.FNUMBER = '{4}' and b.FNUMBER = '{5}'
                                                                                         )
                                                                       set @cnybalance{6} = ( select F_HS_CNYBalance from T_BD_CUSTOMER a 
                                                                                              inner join T_ORG_ORGANIZATIONS b on a.FUSEORGID = b.FORGID
                                                                                              where a.FNUMBER = '{7}' and b.FNUMBER = '{8}'
                                                                                            )
                                                                       set @creditbalance{9} = ( select F_HS_SurplusCreditUSD from T_BD_CUSTOMER a 
                                                                                              inner join T_ORG_ORGANIZATIONS b on a.FUSEORGID = b.FORGID
                                                                                              where a.FNUMBER = '{10}' and b.FNUMBER = '{11}'
                                                                                        )
                                                            ", i, i, i, i, order.F_HS_B2CCustId, order.FSaleOrgId, i, order.F_HS_B2CCustId, order.FSaleOrgId, i, order.F_HS_B2CCustId, order.FSaleOrgId) + System.Environment.NewLine;

                                            if (order.F_HS_BalanceRechargeUSD < 0)
                                            {
                                                execSql += string.Format(@"/*dialect*/ insert into HS_T_customerBalance(F_HS_TradeType,F_HS_UseOrgId,F_HS_B2CCUSTID,changedAmount,changedType,changedCause
                                                                        ,balanceAmount,F_HS_RateToUSA,FSETTLECURRID,changedAmountUSA,balanceAmountUSA,F_HS_CNYBalance,updateTime
                                                                        ,updateUser,FBillNo,fentryID,needfreezed,remark) values ('{0}',{1},{2},{3},'{4}','{5}',@balance{6}*{7},{8},{9}
                                                                        ,{10},@balance{11}, @cnybalance{12},'{13}',{14},'{15}',{16},{17},'{18}')", "余额", SQLUtils.GetOrgId(ctx, order.FSaleOrgId), SQLUtils.GetCustomerId(ctx, order.F_HS_B2CCustId, 1)
                                                                         , order.F_HS_BalanceRechargeUSD * order.F_HS_RateToUSA, order.ChangedType, order.ChangedCause, i, order.F_HS_RateToUSA, order.F_HS_RateToUSA, SQLUtils.GetSettleCurrId(ctx, order.FSettleCurrId)
                                                                         , order.F_HS_BalanceRechargeUSD, i, i, DateTime.Now, ctx.UserId, order.FBillNo, order.FEntryId, order.NeedFreezed == false ? 0 : 1, order.Remark
                                                                         );
                                            }
                                            if (order.F_HS_CreditLineRechargeUSD < 0)
                                            {
                                                execSql += string.Format(@"/*dialect*/ insert into HS_T_customerBalance(F_HS_TradeType,F_HS_UseOrgId,F_HS_B2CCUSTID,changedAmount,changedType,changedCause
                                                                        ,balanceAmount,F_HS_RateToUSA,FSETTLECURRID,changedAmountUSA,balanceAmountUSA,F_HS_CNYBalance,updateTime
                                                                        ,updateUser,FBillNo,fentryID,needfreezed,remark) values ('{0}',{1},{2},{3},'{4}','{5}',@creditbalance{6}*{7},{8},{9}
                                                                        ,{10},@creditbalance{11}, @cnybalance{12},'{13}',{14},'{15}',{16},{17},'{18}') "
                                                                         , "信用额度", SQLUtils.GetOrgId(ctx, order.FSaleOrgId), SQLUtils.GetCustomerId(ctx, order.F_HS_B2CCustId, 1)
                                                                         , order.F_HS_CreditLineRechargeUSD * order.F_HS_RateToUSA, order.ChangedType, order.ChangedCause, i, order.F_HS_RateToUSA, order.F_HS_RateToUSA, SQLUtils.GetSettleCurrId(ctx, order.FSettleCurrId)
                                                                         , order.F_HS_CreditLineRechargeUSD, i, i, DateTime.Now, ctx.UserId, order.FBillNo, order.FEntryId, order.NeedFreezed == false ? 0 : 1, order.Remark
                                                                         ) + System.Environment.NewLine;
                                            }
                                        }

                                        else
                                        {
                                            execSql += string.Format(@"declare @balance{2} decimal(10,2)
                                                                   declare @cnybalance{4} decimal(10,2)
                                                                   set @balance{3} = ( select F_HS_USDBalance from T_BD_CUSTOMER a 
                                                                                       inner join T_ORG_ORGANIZATIONS b on a.FUSEORGID = b.FORGID
                                                                                       where a.FNUMBER = '{0}' and b.FNUMBER = '{1}'
                                                                                     )
                                                                   set @cnybalance{5} = ( select F_HS_CNYBalance from T_BD_CUSTOMER a 
                                                                                          inner join T_ORG_ORGANIZATIONS b on a.FUSEORGID = b.FORGID
                                                                                          where a.FNUMBER = '{6}' and b.FNUMBER = '{7}'
                                                                                        )
                                                            ", order.F_HS_B2CCustId, order.FSaleOrgId, i, i, i, i, order.F_HS_B2CCustId, order.FSaleOrgId) + System.Environment.NewLine;

                                            execSql += string.Format(@"/*dialect*/ insert into HS_T_customerBalance(F_HS_TradeType,F_HS_UseOrgId,F_HS_B2CCUSTID,changedAmount,changedType,changedCause
                                                                    ,balanceAmount,F_HS_RateToUSA,FSETTLECURRID,changedAmountUSA,balanceAmountUSA,F_HS_CNYBalance,updateTime
                                                                    ,updateUser,FBillNo,fentryID,needfreezed,remark) values ('{18}','{15}','{0}',{1},'{2}','{3}',@balance{13}*{17},{4},{5}
                                                                    ,{6},@balance{14}, @cnybalance{16},'{7}',{8},'{9}',{10},{11},'{12}') ", SQLUtils.GetCustomerId(ctx, order.F_HS_B2CCustId, 1), order.FRealAmountFor
                                                                     , order.ChangedType, order.ChangedCause, order.F_HS_RateToUSA, SQLUtils.GetSettleCurrId(ctx, order.FSettleCurrId)
                                                                     , order.FRealAmountFor_USD, DateTime.Now, ctx.UserId, order.FBillNo, order.FEntryId, order.NeedFreezed == false ? 0 : 1, order.Remark, i, i
                                                                     , SQLUtils.GetOrgId(ctx, order.FSaleOrgId), i, order.F_HS_RateToUSA, "余额") + System.Environment.NewLine;
                                        }


                                        sql = string.Empty;
                                        i++;
                                    }
                                }
                                else
                                {
                                    LogUtils.WriteSynchroLog(ctx, this.DataType, "获取【" + order.FSettleCurrId + "币别】兑美元的实时汇率失败");
                                    throw new Exception("获取【" + order.FSettleCurrId + "币别】兑美元的实时汇率失败!");
                                }
                            }
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                LogUtils.WriteSynchroLog(ctx, this.DataType, ex.Message + System.Environment.NewLine + ex.StackTrace);
            }
            return(execSql);
        }
Esempio n. 4
0
        /// <summary>
        /// 执行同步客户操作
        /// </summary>
        /// <param name="sourceDatas"></param>
        /// <param name="logs"></param>
        /// <param name="operationType"></param>
        /// <returns></returns>
        public override HttpResponseResult ExecuteSynchro(IEnumerable <AbsSynchroDataInfo> sourceDatas, List <SynchroLog> logs, SynOperationType operationType)
        {
            HttpResponseResult    result = null;
            List <K3CustomerInfo> custs  = null;

            JObject bizData = null;
            string  msgs    = string.Empty;

            if (sourceDatas != null && sourceDatas.Count() > 0)
            {
                custs   = sourceDatas.Select(c => (K3CustomerInfo)c).ToList();
                bizData = BuildSynchroDataJsons(sourceDatas, operationType);
            }
            try
            {
                if (operationType == SynOperationType.SAVE)
                {
                    if (bizData == null)
                    {
                        return(null);
                    }
                    else
                    {
                        if (bizData["Model"] == null)
                        {
                            return(null);
                        }
                    }
                    //客户地址新增
                    result = ExecuteOperate(SynOperationType.SAVE, null, null, bizData.ToString());

                    //客户地址新增成功后返回的单据编码集合
                    if (result != null && result.Success)
                    {
                        RemoveRedisData(this.K3CloudContext, result.SuccessEntityNos);
                    }
                }
                else if (operationType == SynOperationType.UPDATE)
                {
                    List <SqlObject> sqlObjects = null;
                    List <SqlParam>  sqlParams  = null;
                    List <string>    custNos    = new List <string>();

                    int count = 0;

                    try
                    {
                        if (custs != null && custs.Count > 0)
                        {
                            custNos = new List <string>();

                            foreach (var cust in custs)
                            {
                                if (cust != null && cust.lstCustCtaInfo != null && cust.lstCustCtaInfo.Count > 0)
                                {
                                    foreach (var contact in cust.lstCustCtaInfo)
                                    {
                                        if (contact != null)
                                        {
                                            string sql = string.Format(@"/*dialect*/ update a 
                                                                            set FNAME = @FNAME,FADDRESS = @FADDRESS,FMOBILE = @FMOBILE,F_HS_POSTCODE = @F_HS_POSTCODE,
                                                                            F_HS_DELIVERYCITY = @F_HS_DELIVERYCITY,F_HS_DELIVERYPROVINCES = @F_HS_DELIVERYPROVINCES
                                                                            ,F_HS_RECIPIENTCOUNTRY = @F_HS_RECIPIENTCOUNTRY,F_HS_DELIVERYNAME = @F_HS_DELIVERYNAME
                                                                            from T_BD_CUSTLOCATION a
                                                                            inner join T_BD_CUSTOMER b
                                                                            on a.FCUSTID = b.FCUSTID
                                                                            where b.FNUMBER = @BFNUMBER 
                                                                            and a.FNUMBER = @AFNUMBER
                                                                            and FUSEORGID = 1");

                                            sqlObjects = new List <SqlObject>();
                                            sqlParams  = new List <SqlParam>();

                                            sqlParams.Add(new SqlParam("@FNAME", KDDbType.String, SQLUtils.DealQuotes(contact.FNAME1)));
                                            sqlParams.Add(new SqlParam("@FADDRESS", KDDbType.String, SQLUtils.DealQuotes(contact.FADDRESS1)));
                                            sqlParams.Add(new SqlParam("@FMOBILE", KDDbType.String, SQLUtils.DealQuotes(contact.FMOBILE)));
                                            sqlParams.Add(new SqlParam("@F_HS_POSTCODE", KDDbType.String, SQLUtils.DealQuotes(contact.F_HS_PostCode)));
                                            sqlParams.Add(new SqlParam("@F_HS_DELIVERYCITY", KDDbType.String, SQLUtils.DealQuotes(contact.F_HS_DeliveryCity)));
                                            sqlParams.Add(new SqlParam("@F_HS_DELIVERYPROVINCES", KDDbType.String, SQLUtils.DealQuotes(contact.F_HS_DeliveryProvinces)));
                                            sqlParams.Add(new SqlParam("@F_HS_RECIPIENTCOUNTRY", KDDbType.String, SQLUtils.DealQuotes(SQLUtils.GetCountryId(this.K3CloudContext, contact.F_HS_RecipientCountry))));
                                            sqlParams.Add(new SqlParam("@F_HS_DELIVERYNAME", KDDbType.String, SQLUtils.DealQuotes(contact.F_HS_DeliveryName)));
                                            sqlParams.Add(new SqlParam("@BFNUMBER", KDDbType.String, contact.FCustNo));
                                            sqlParams.Add(new SqlParam("@AFNUMBER", KDDbType.String, contact.FNUMBER1));
                                            sqlObjects.Add(new SqlObject(sql, sqlParams));

                                            count = DBUtils.ExecuteBatch(this.K3CloudContext, sqlObjects);

                                            if (count > 0)
                                            {
                                                custNos.Add(contact.FCustNo);
                                                msgs += string.Format("客户[{0}]地址[{1}]更新成功!", contact.FCustNo, contact.FNUMBER1) + Environment.NewLine;
                                                LogUtils.WriteSynchroLog(this.K3CloudContext, SynchroDataType.CustomerAddress, string.Format("客户[{0}]地址[{1}]更新成功!", contact.FCustNo, contact.FNUMBER1));
                                            }
                                        }
                                    }
                                }
                            }

                            if (!string.IsNullOrWhiteSpace(msgs))
                            {
                                result                  = new HttpResponseResult();
                                result.Success          = true;
                                result.SuccessEntityNos = custNos;
                                result.Message          = msgs;

                                RemoveRedisData(this.K3CloudContext, custNos);
                            }
                        }
                    }
                    catch (Exception ex)
                    {
                        result         = new HttpResponseResult();
                        result.Success = false;
                        result.Message = "客户地址更新出现异常:" + ex.Message + Environment.NewLine + ex.StackTrace;
                        LogUtils.WriteSynchroLog(this.K3CloudContext, SynchroDataType.CustomerAddress, "客户地址更新出现异常:" + result.Message);
                    }
                }
                return(result);
            }
            catch (Exception ex)
            {
                if (logs != null && logs.Count > 0)
                {
                    foreach (var log in logs)
                    {
                        log.IsSuccess = 0;
                        log.ErrInfor  = ex.Message + System.Environment.NewLine + ex.StackTrace;
                    }
                }
                LogUtils.WriteSynchroLog(this.K3CloudContext, this.DataType, ex.Message + System.Environment.NewLine + ex.StackTrace);
            }

            if (result == null)
            {
                return(null);
            }

            if (result.Success == false && result.FailedResult == null && result.Result == null)
            {
                //同步出现错误之类:如令牌错误,url错误之类的
                if (logs != null && logs.Count > 0)
                {
                    foreach (var log in logs)
                    {
                        log.IsSuccess = 0;
                        log.ErrInfor  = "数据同步失败:" + result.Message == null ? "" : result.Message;
                    }
                }

                return(result);
            }

            return(result);
        }
Esempio n. 5
0
        /// <summary>
        /// 当list_ID基础资料.不覆盖物料名称==true,则仅更新物料.ListName ,不更新物料.FName 否则同时更新物料.ListName ,物料.FName
        ///物料列表审核时,更新积分返点率(澳洲2C积分返点率)的值(服务类物料除外):  ”液体:1 ;硬件:5,清仓品:0
        /// </summary>
        /// <param name="ctx"></param>
        /// <param name="datas"></param>
        /// <returns></returns>
        private int UpdateMaterialInfo(Context ctx, IEnumerable <AbsSynchroDataInfo> datas)
        {
            int count = 0;

            List <Material>  materials  = null;
            string           sql        = string.Empty;
            List <SqlObject> sqlObjects = null;
            List <SqlParam>  sqlParams  = null;
            SqlParam         sqlParam   = null;
            SqlParam         sqlParam1  = null;
            SqlObject        sqlObject  = null;


            if (datas != null && datas.Count() > 0)
            {
                materials = datas.Select(d => (Material)d).ToList();
            }

            if (materials != null && materials.Count() > 0)
            {
                sqlObjects = new List <SqlObject>();

                if (this.FormId.CompareTo(HSFormIdConst.Material) == 0)
                {
                    foreach (var info in materials)
                    {
                        if (info != null)
                        {
                            if (materials != null && materials.Count > 0)
                            {
                                foreach (var material in materials)
                                {
                                    sql = string.Format(@"/*dialect*/update a set a.F_HS_IntegralReturnRate = @F_HS_IntegralReturnRate
                                                            from T_BD_MATERIAL a 
											                where a.FNUMBER not like '99.%'
											                and a.FNUMBER = @FNUMBER
											                "                                            ) + System.Environment.NewLine;

                                    sqlParams = new List <SqlParam>();
                                    sqlParam  = new SqlParam("@F_HS_IntegralReturnRate", KDDbType.Decimal, material.F_HS_IntegralReturnRate);
                                    sqlParam1 = new SqlParam("@FNUMBER", KDDbType.String, material.FNumber);
                                    sqlParams.Add(sqlParam);
                                    sqlParams.Add(sqlParam1);
                                    sqlObject = new SqlObject(sql, sqlParams);
                                    sqlObjects.Add(sqlObject);
                                }
                            }
                        }
                    }
                }

                if (this.FormId.CompareTo(HSFormIdConst.HS_List_ID) == 0)
                {
                    foreach (var info in materials)
                    {
                        if (info != null)
                        {
                            sql = string.Format(@"/*dialect*/update a set a.F_HS_LISTNAME = @F_HS_LISTNAME
                                                    from T_BD_MATERIAL a 
											        inner join HS_T_BD_LISTID k on k.FID = a.F_HS_ListIDNew
											        where a.FNUMBER not like '99.%'
											        and k.FNUMBER = @FNUMBER
											        "                                            ) + System.Environment.NewLine;

                            sqlParams = new List <SqlParam>();
                            sqlParam  = new SqlParam("@F_HS_LISTNAME", KDDbType.String, SQLUtils.DealQuotes(info.F_HS_ListName));
                            sqlParam1 = new SqlParam("@FNUMBER", KDDbType.String, info.F_HS_ListID);
                            sqlParams.Add(sqlParam);
                            sqlParams.Add(sqlParam1);
                            sqlObject = new SqlObject(sql, sqlParams);
                            sqlObjects.Add(sqlObject);

                            if (!info.F_HS_NotCoverMaterialName)
                            {
                                sql = string.Format(@"/*dialect*/update b set b.FName  = @FName
                                                                from T_BD_MATERIAL a 
                                                                inner join T_BD_MATERIAL_L b on b.FMATERIALID = a.FMATERIALID and b.FLOCALEID=2052
                                                                inner join HS_T_BD_LISTID k on k.FID = a.F_HS_ListIDNew
											                    where a.FNUMBER not like '99.%'
											                    and k.FNUMBER = @FNUMBER"                                            );

                                sqlParams = new List <SqlParam>();
                                sqlParam  = new SqlParam("@FName", KDDbType.String, SQLUtils.DealQuotes(info.F_HS_ListName));
                                sqlParam1 = new SqlParam("@FNUMBER", KDDbType.String, info.F_HS_ListID);
                                sqlParams.Add(sqlParam);
                                sqlParams.Add(sqlParam1);
                                sqlObject = new SqlObject(sql, sqlParams);
                                sqlObjects.Add(sqlObject);
                            }
                        }
                    }
                }

                count = DBUtils.ExecuteBatch(ctx, sqlObjects);
            }

            return(count);
        }
Esempio n. 6
0
        public override HttpResponseResult ExecuteSynchro(IEnumerable <AbsSynchroDataInfo> sourceDatas, List <SynchroLog> logs, SynOperationType operationType)
        {
            HttpResponseResult    result       = new HttpResponseResult();
            List <K3SalOrderInfo> second       = null;
            List <string>         numbers      = null;
            List <string>         auditSuccNos = null;

            if (sourceDatas == null || sourceDatas.Count() == 0)
            {
                result         = new HttpResponseResult();
                result.Success = false;
                result.Message = "没有需要同步的数据!";
            }

            if (operationType == SynOperationType.UPDATE)
            {
                try
                {
                    second = sourceDatas.Select(o => (K3SalOrderInfo)o).ToList();

                    if (second != default(List <K3SalOrderInfo>))
                    {
                        if (second.Count > 0)
                        {
                            numbers      = new List <string>();
                            auditSuccNos = new List <string>();

                            foreach (var item in second)
                            {
                                if (IsExist(this.K3CloudContext, item))
                                {
                                    char isSameAdress = default(char);

                                    if (item.F_HS_IsSameAdress)
                                    {
                                        isSameAdress = '1';
                                    }
                                    else
                                    {
                                        isSameAdress = '0';
                                    }
                                    string uSql  = string.Format(@"/*dialect*/ update T_SAL_ORDER set F_HS_PAYMENTSTATUS = '{0}',F_HS_SALEORDERSOURCE = '5a97d3123e9dff',F_HS_BillAddress = '{1}',F_HS_IsSameAdress = '{2}',F_HS_PaymentModeNew = '{4}' where FBILLNO = '{3}' and FDOCUMENTSTATUS != 'C' and FDOCUMENTSTATUS != 'D' and FDOCUMENTSTATUS != 'B' and FBILLNO <>''", item.F_HS_PaymentStatus, SQLUtils.DealQuotes(item.F_HS_BillAddress), isSameAdress, item.FBillNo, SQLUtils.GetPaymentMethodId(this.K3CloudContext, item.F_HS_PaymentModeNew));
                                    int    count = DBUtils.Execute(this.K3CloudContext, uSql);

                                    if (count > 0 && item.F_HS_PaymentStatus != null && item.F_HS_PaymentStatus.CompareTo("3") == 0)
                                    {
                                        numbers.Add(item.FBillNo);
                                    }
                                }
                                else
                                {
                                    auditSuccNos.Add(item.FBillNo);

                                    result.Message += "编码为【" + item.FBillNo + "】的订单已经审核" + System.Environment.NewLine;
                                    result.Success  = false;
                                }
                            }

                            if (numbers != null && numbers.Count > 0)
                            {
                                //单据提交
                                result = ExecuteOperate(SynOperationType.SUBMIT, numbers, null, null);

                                if (result != null && result.SuccessEntityNos != null && result.SuccessEntityNos.Count > 0)
                                {
                                    //单据审核
                                    result = ExecuteOperate(SynOperationType.AUDIT, result.SuccessEntityNos, null, null);

                                    if (result != null && result.SuccessEntityNos != null && result.SuccessEntityNos.Count > 0)
                                    {
                                        List <K3SalOrderInfo> auditOrders = null;
                                        //审核成功后的销售订单
                                        if (result.Success)
                                        {
                                            auditOrders = GetSelectedSalOrders(first, result.SuccessEntityNos);
                                        }
                                        else
                                        {
                                            auditOrders = GetSelectedSalOrders(first, GetAuditedSalOrderNos(this.K3CloudContext, second));
                                        }

                                        //第二次同步后的销售订单信息和第一次同步的销售订单信息合成新的销售订单列表信息(获取完整的销售订单信息)
                                        auditOrders = CombineSalOrder(second, auditOrders);
                                        //从redis再次获取数据
                                        if (auditOrders == null || auditOrders.Count == 0)
                                        {
                                            //auditOrders = GetAuditedSalOrderDatas(ctx, second);
                                            if (second != null)
                                            {
                                                auditOrders = GetSalOrdersByDb(this.K3CloudContext, second.Select(o => o.FBillNo).ToList());
                                            }
                                        }
                                        //同步收款单
                                        if (auditOrders != null)
                                        {
                                            Dictionary <SynOperationType, IEnumerable <AbsSynchroDataInfo> > dict = new Dictionary <SynOperationType, IEnumerable <AbsSynchroDataInfo> >();
                                            dict.Add(SynOperationType.SAVE, auditOrders);

                                            HttpResponseResult respone = SynchroDataHelper.SynchroDataToK3(this.K3CloudContext, SynchroDataType.ReceiveBill, true, null, dict);
                                            //收款单同步成功后删除销售订单记录
                                            if (respone != null)
                                            {
                                                first.RemoveWhere(o => respone.SuccessEntityNos.Contains(o.FBillNo));
                                            }
                                        }

                                        //更新客户下单次数
                                        StatisticsOrderCount(this.K3CloudContext, result.SuccessEntityNos);
                                        //审核成功后删除Redis中的数据(销售订单第二次同步)
                                        RemoveRedisData(this.K3CloudContext, result.SuccessEntityNos);
                                    }
                                }
                            }
                        }
                    }
                    else
                    {
                        LogUtils.WriteSynchroLog(this.K3CloudContext, this.DataType, "未找到需要同步的数据!");
                    }
                }
                catch (Exception ex)
                {
                    LogUtils.WriteSynchroLog(this.K3CloudContext, this.DataType, "数据批量更新过程中出现异常,异常信息:" + ex.Message + System.Environment.NewLine + ex.StackTrace);
                }
            }

            return(result);
        }