예제 #1
0
        /// <summary>
        /// 新增下载
        /// </summary>
        /// <param name="downloadNum"></param>
        /// <returns></returns>
        public ActionResult DownloadMoveCarQRCode(int downloadNum)
        {
            var workbook = new XSSFWorkbook();
            var sheet    = workbook.CreateSheet();
            var index    = 0;
            var row      = sheet.CreateRow(index++);

            var num = 0;

            row.CreateCell(num++).SetCellValue("二维码");
            row.CreateCell(num++).SetCellValue("使用状态");
            row.CreateCell(num++).SetCellValue("生成时间");

            num = 0;
            sheet.SetColumnWidth(num++, 16 * 256);
            sheet.SetColumnWidth(num++, 16 * 256);
            sheet.SetColumnWidth(num++, 16 * 256);
            var exm = new MoveCarQRCodeManager();

            //更新途虎挪车二维码表的下载flag为true 并获取更新flag的列表
            var list = exm.UpdateDownloadFlagAndSelectMoveCarQRCode(downloadNum, User.Identity.Name);


            //修改途虎挪车二维码总下载记录
            var existTotalModel  = exm.GetMoveCarTotalRecord();
            var totalRecordModel = new MoveCarTotalRecordsModel();

            totalRecordModel.GeneratedNum  = 0;
            totalRecordModel.DownloadedNum = downloadNum;
            exm.AddOrUpdateMoveCarTotalRecord(totalRecordModel, 1);

            string bingStatus = string.Empty;

            foreach (var item in list)
            {
                row = sheet.CreateRow(index++);
                num = 0;
                if (item.IsBinding == false)
                {
                    bingStatus = "未绑定";
                }
                else
                {
                    bingStatus = "已绑定";
                }
                row.CreateCell(num++).SetCellValue(item.QRCodeImageUrl);
                row.CreateCell(num++).SetCellValue(bingStatus);
                row.CreateCell(num++).SetCellValue(item.CreateDatetime.ToString("yyyy-MM-dd HH:mm:ss"));
            }
            var ms = new MemoryStream();

            workbook.Write(ms);
            return(File(ms.ToArray(), "application/x-xls", $"下载途虎挪车二维码-{DateTime.Now.ToString("yyyy年MM月dd日HH时mm分ss秒")}-{downloadNum}.xlsx"));
        }
예제 #2
0
        /// <summary>
        /// 获取途虎挪车二维码总生成下载记录
        /// </summary>
        /// <param name="conn"></param>
        /// <returns></returns>
        public MoveCarTotalRecordsModel GetMoveCarTotalRecordsModel()
        {
            var result = new MoveCarTotalRecordsModel();

            try
            {
                using (var conn = ProcessConnection.OpenGungnirReadOnly)
                {
                    result = dal.GetMoveCarTotalRecordsModel(conn);
                }
            }
            catch (Exception e)
            {
                Logger.Error("GetMoveCarTotalRecordsModel", e);
                throw;
            }
            return(result);
        }
예제 #3
0
        /// <summary>
        /// 添加或修改途虎挪车二维码总生成下载记录
        /// </summary>
        /// <param name="conn"></param>
        /// <param name="model"></param>
        /// <returns></returns>
        public bool AddOrUpdateMoveCarTotalRecord(MoveCarTotalRecordsModel model, int totalRecordCount)
        {
            bool result = false;

            try
            {
                using (var conn = ProcessConnection.OpenGungnir)
                {
                    result = dal.AddOrUpdateMoveCarTotalRecord(conn, model, totalRecordCount);
                }
            }
            catch (Exception e)
            {
                Logger.Error($"AddOrUpdateMoveCarTotalRecord-> {JsonConvert.SerializeObject(model)} -> {totalRecordCount}", e);
                throw;
            }
            return(result);
        }
예제 #4
0
 /// <summary>
 /// 添加或修改途虎挪车二维码总生成下载记录
 /// </summary>
 /// <param name="conn"></param>
 /// <param name="model"></param>
 /// <returns></returns>
 public bool AddOrUpdateMoveCarTotalRecord(SqlConnection conn, MoveCarTotalRecordsModel model, int totalRecordCount)
 {
     #region SQL
     string sqlInsert  = @"
                         INSERT  INTO [Tuhu_profiles].[dbo].[MoveCarTotalRecords]
                                 ( [GeneratedNum] ,
                                   [DownloadedNum] ,
                                   [DownloadableNum] ,
                                   [CreateDatetime] ,
                                   [LastUpdateDateTime] 
                                 )
                         VALUES  ( @GeneratedNum ,
                                   @DownloadedNum ,
                                   @DownloadableNum ,
                                   GETDATE() ,
                                   GETDATE()
                                 );";
     string sqlUpdate1 = @"
                         UPDATE  [Tuhu_profiles].[dbo].[MoveCarTotalRecords] WITH ( ROWLOCK )
                         SET     GeneratedNum = GeneratedNum + @GeneratedNum ,
                                 DownloadedNum = DownloadedNum + @DownloadedNum ,
                                 LastUpdateDateTime = GETDATE() ;";
     string sqlUpdate2 = @"
                         UPDATE  [Tuhu_profiles].[dbo].[MoveCarTotalRecords] WITH ( ROWLOCK )
                         SET     DownloadableNum = GeneratedNum - DownloadedNum";
     #endregion
     var parameters = new[]
     {
         new SqlParameter("@GeneratedNum", model.GeneratedNum),
         new SqlParameter("@DownloadedNum", model.DownloadedNum),
         new SqlParameter("@DownloadableNum", model.DownloadableNum)
     };
     if (totalRecordCount == 0)
     {
         return(Convert.ToInt32(SqlHelper.ExecuteScalar(conn, CommandType.Text, sqlInsert, parameters)) > 0);
     }
     else
     {
         SqlHelper.ExecuteNonQuery(conn, CommandType.Text, sqlUpdate1, parameters);
         return(SqlHelper.ExecuteNonQuery(conn, CommandType.Text, sqlUpdate2, parameters) > 0);
     }
 }