Ejemplo n.º 1
0
        private OptResult RecoverSingle(SingleProcessParam param)
        {
            OptResult rst       = null;
            var       operation = CardOperation.Recover;
            var       optDesc   = operation.GetDescription() + "(单账户)";

            if (param.card == null)
            {
                rst = OptResult.Build(ResultCode.DataNotFound, string.Format("{0}——一卡通账户不存在!", optDesc));
                return(rst);
            }
            if (param.card.State == CardState.Normal)//"正常"状态的账户无需恢复
            {
                rst = OptResult.Build(ResultCode.Success,
                                      string.Format("{0}——身份证号为{1}的账户状态为{2},无需恢复!", optDesc, param.card.card_idcard, param.card.State.GetDescription()));
                return(rst);
            }
            //2、数据库处理

            /*
             * 流程:
             * 1)更新card_info
             * 2)新增操作记录,type:注销
             * 3)新增一卡通流水
             */
            var rec_id     = GuidExtension.GetOne();
            var optTime    = DateTime.Now;
            var cardRecord = new CardRecord
            {
                rec_id       = rec_id,
                rec_number   = param.card.card_number,
                rec_username = param.card.card_username,
                rec_idcard   = param.card.card_idcard,
                rec_type     = operation.ToString(),
                rec_time     = optTime,
                rec_operator = param.opt,
                rec_remark   = optDesc
            };

            var innerTran = param.tran;

            if (innerTran == null)
            {
                innerTran = _cardInfoRep.Begin();
            }
            try
            {
                //1
                var count = _cardInfoRep.UpdateBySqlName(SqlName_Update,
                                                         new { card_idcard = param.card.card_idcard, card_state = CardState.Normal.ToString(), card_modifier = param.opt, card_modifytime = optTime },
                                                         new string[] { "card_state", "card_modifier", "card_modifytime" },
                                                         innerTran);
                if (count < 1)
                {
                    if (param.tran == null)
                    {
                        //外部事务为null,说明是本方法内部事务,这里自行回滚
                        innerTran.Rollback();
                    }
                    rst = OptResult.Build(ResultCode.Fail, string.Format("{0}——idcard={1}", optDesc, param.card.card_idcard));
                    return(rst);
                }
                //2
                _cardRecordRep.Insert(cardRecord, innerTran);
                if (param.tran == null)
                {
                    //外部事务为null,说明是本方法内部事务,这里自行提交
                    innerTran.Commit();
                }
                rst = OptResult.Build(ResultCode.Success, string.Format("{0}——idcard={1}", optDesc, param.card.card_idcard));
            }
            catch (Exception ex)
            {
                LogHelper.LogError(optDesc, ex);
                rst = OptResult.Build(ResultCode.DbError, optDesc);
                return(rst);
            }

            return(rst);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// 通用批量处理方法
        /// </summary>
        /// <param name="idcards">身份证号列表</param>
        /// <param name="opt">操作员</param>
        /// <param name="processDes">本次操作描述</param>
        /// <param name="funcSingle">单次操作委托</param>
        /// <param name="funcSingle">单次操作委托所需参数的构造器</param>
        /// <returns></returns>
        protected OptResult BatchProcess(IEnumerable <string> idcards, string opt, string processDes, Func <SingleProcessParam, OptResult> funcSingle, Func <SingleProcessParam> paramGetter = null)
        {
            OptResult rst = null;

            if (idcards == null || idcards.Count() < 1)
            {
                rst = OptResult.Build(ResultCode.ParamError, string.Format("{0}——身份证号列表不能为空!", processDes));
                return(rst);
            }
            if (funcSingle == null)
            {
                rst = OptResult.Build(ResultCode.ParamError, string.Format("{0}——未指定funcSingle参数!", processDes));
                return(rst);
            }
            var discinctIdcards = idcards.Distinct();

            var where = Predicates.Field <CardInfo>(c => c.card_idcard, Operator.Eq, discinctIdcards);//这里sql查询条件会转换为in
            var cards = _cardInfoRep.GetList(where);

            if (cards == null || cards.Count() < 1)
            {
                rst = OptResult.Build(ResultCode.DataNotFound, string.Format("{0}——未找到指定身份证号的一卡通账户!", processDes));
                return(rst);
            }

            var tran = base.Begin();

            try
            {
                bool succeed             = true;
                SingleProcessParam param = null;
                foreach (var card in cards)
                {
                    if (paramGetter != null)
                    {
                        param      = paramGetter();
                        param.card = card;
                        param.opt  = opt;
                        param.tran = tran;
                    }
                    else
                    {
                        param = new SingleProcessParam {
                            card = card, opt = opt, tran = tran
                        };
                    }
                    rst = funcSingle(param);
                    if (rst.code != ResultCode.Success)
                    {
                        try
                        {
                            tran.Rollback();
                        }
                        catch { }
                        succeed = false;
                        break;
                    }
                }
                if (succeed)
                {
                    tran.Commit();
                    rst = OptResult.Build(ResultCode.Success, string.Format("{0}", processDes));
                }
            }
            catch (Exception ex)
            {
                LogHelper.LogError(processDes, ex);
                rst = OptResult.Build(ResultCode.DbError, string.Format("{0}", processDes));
            }
            return(rst);
        }
Ejemplo n.º 3
0
        //私有方法

        private OptResult CloseDownSingle(SingleProcessParam param)
        {
            OptResult rst       = null;
            var       operation = CardOperation.CloseDwn;
            var       optDesc   = operation.GetDescription() + "(单账户)";

            if (param.card == null)
            {
                rst = OptResult.Build(ResultCode.DataNotFound, string.Format("{0}——一卡通账户不存在!", optDesc));
                return(rst);
            }
            if (param.card.State != CardState.Normal)//暂定只有正常状态的账户才能注销
            {
                rst = OptResult.Build(ResultCode.Fail,
                                      string.Format("{0}——身份证号为{1}的账户状态为{2},不能注销!", optDesc, param.card.card_idcard, param.card.State.GetDescription()));
                return(rst);
            }
            //2、数据库处理

            /*
             * 流程:
             * 1)更新card_info
             * 2)新增操作记录,type:注销
             * 3)新增一卡通流水
             */
            var rec_id     = GuidExtension.GetOne();
            var optTime    = DateTime.Now;
            var cardRecord = new CardRecord
            {
                rec_id       = rec_id,
                rec_number   = param.card.card_number,
                rec_username = param.card.card_username,
                rec_idcard   = param.card.card_idcard,
                rec_type     = operation.ToString(),
                rec_time     = optTime,
                rec_operator = param.opt,
                rec_remark   = string.Format("{0}——本次变动额:{1}", optDesc, param.card.card_govmoney + param.card.card_mymoney)
            };

            var cardBill = new CardBill
            {
                bill_id        = Guid.NewGuid().ToString("N"),
                bill_number    = param.card.card_number,
                bill_idcard    = param.card.card_idcard,
                bill_agoall    = param.card.card_govmoney + param.card.card_mymoney,
                bill_agogov    = param.card.card_govmoney,
                bill_agomy     = param.card.card_mymoney,
                bill_changegov = -param.card.card_govmoney,
                bill_changemy  = -param.card.card_mymoney,
                bill_nowall    = 0,
                bill_nowgov    = 0,
                bill_nowmy     = 0,
                bill_type      = operation.ToString(),
                bill_time      = optTime,
                bill_record    = rec_id,
                bill_remark    = optDesc
            };

            var innerTran = param.tran;

            if (innerTran == null)
            {
                innerTran = _cardInfoRep.Begin();
            }
            try
            {
                //1
                var count = _cardInfoRep.UpdateBySqlName(SqlName_Update,
                                                         new { card_govmoney = 0, card_mymoney = 0, card_idcard = param.card.card_idcard, card_state = CardState.Off.ToString(), card_modifier = param.opt, card_modifytime = optTime },
                                                         new string[] { "card_govmoney", "card_mymoney", "card_state", "card_modifier", "card_modifytime" },
                                                         innerTran);
                if (count < 1)
                {
                    if (param.tran == null)
                    {
                        //外部事务为null,说明是本方法内部事务,这里自行回滚
                        innerTran.Rollback();
                    }
                    rst = OptResult.Build(ResultCode.Fail, string.Format("{0}——idcard={1}", optDesc, param.card.card_idcard));
                    return(rst);
                }
                //2
                _cardRecordRep.Insert(cardRecord, innerTran);
                //3
                _cardBillRep.Insert(cardBill, innerTran);
                if (param.tran == null)
                {
                    //外部事务为null,说明是本方法内部事务,这里自行提交
                    innerTran.Commit();
                }
                rst = OptResult.Build(ResultCode.Success, string.Format("{0}——idcard={1}", optDesc, param.card.card_idcard));
            }
            catch (Exception ex)
            {
                LogHelper.LogError(optDesc, ex);
                rst = OptResult.Build(ResultCode.DbError, optDesc);
                return(rst);
            }

            return(rst);
        }