Beispiel #1
0
        public ActionResult UpdateWorkHours(SysAnchorLiveRecordEntity model)
        {
            var result = sysUserAnchorLogic.UpdateWorkHours(model);

            if (result)
            {
                return(Success());
            }
            return(Error());
        }
Beispiel #2
0
        /// <summary>
        /// 编辑工时记录
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public bool UpdateWorkHours(SysAnchorLiveRecordEntity model)
        {
            var result = 0;

            using (var db = GetSqlSugarDB(DbConnType.QPVideoAnchorDB))
            {
                try
                {
                    db.Ado.BeginTran();
                    var     opdate   = model.ontime.Date;
                    var     aid      = db.Queryable <SysAnchorLiveRecordEntity>().Where(it => it.seqid == model.seqid).Select(it => it.aid).First();
                    decimal liveTime = (decimal)model.uptime.Subtract(model.ontime).TotalMinutes;
                    result = db.Updateable <SysAnchorLiveRecordEntity>().SetColumns(it => new SysAnchorLiveRecordEntity {
                        livetime = liveTime, ontime = model.ontime, uptime = model.uptime
                    }).Where(it => it.seqid == model.seqid).ExecuteCommand();
                    //判断报表数据是否存在
                    var incomeModel = db.Queryable <SysIncomeEntity>().Where(it => it.AnchorID == aid && it.opdate == opdate).First();
                    //获取修改时间当天的 直播时长和
                    decimal sumLiveTime = db.Queryable <SysAnchorLiveRecordEntity>()
                                          .Where(it => it.aid == aid && it.ontime >= opdate && it.ontime < opdate.AddDays(1))
                                          .Select(it => SqlFunc.AggregateSum(it.livetime)).First();
                    if (incomeModel == null)
                    {
                        db.Insertable(new SysIncomeEntity
                        {
                            AnchorID = aid,
                            opdate   = opdate,
                            livetime = sumLiveTime,
                        }).ExecuteCommand();
                    }
                    else
                    {
                        incomeModel.livetime = sumLiveTime;
                        db.Updateable(incomeModel).UpdateColumns(it => new { it.livetime }).ExecuteCommand();
                    }
                    db.Ado.CommitTran();
                }
                catch (Exception ex)
                {
                    db.Ado.RollbackTran();
                    new LogLogic().Write(Level.Error, "编辑工时记录", ex.Message, ex.StackTrace);
                }
            }
            return(result > 0);
        }