/// <summary> /// 获取分页的数据 /// </summary> /// <param name="model">查询条件实体</param> /// <param name="carType">查询的卡类</param> /// <returns></returns> public List <CardServiceModel> GetCardPage(CardServiceSearchModel model, CarTypeEnum carType) { try { List <CardServiceModel> list = null; switch (carType) { case CarTypeEnum.TempCar: list = _tempCardDatabaseoperate.GetFromDataBaseByPage(model) as List <CardServiceModel>; break; case CarTypeEnum.MonthCar: list = _monthCardDatabaseoperate.GetFromDataBaseByPage(model) as List <CardServiceModel>; break; case CarTypeEnum.ValueCar: list = _valueCardDatabaseoperate.GetFromDataBaseByPage(model) as List <CardServiceModel>; break; case CarTypeEnum.VIPCar: list = _monthCardDatabaseoperate.GetFromDataBaseByPage(model) as List <CardServiceModel>; break; } if (list != null) { list = list.OrderByDescending(a => a.StartDate).ToList();//降序 } return(list); } catch (Exception ex) { return(null); } }
public IHttpActionResult GetTempCardList(TempCardSearchRequest requestModel) { ResponseBasePaper <CardServiceModel> response = new ResponseBasePaper <CardServiceModel>() { IsSuccess = true, MessageCode = (int)ApiBaseErrorCode.API_SUCCESS, MessageContent = ApiBaseErrorCode.API_SUCCESS.ToString(), Result = new List <CardServiceModel>() }; if (requestModel == null || string.IsNullOrWhiteSpace(requestModel.ProjectGuid) || string.IsNullOrWhiteSpace(requestModel.ParkingCode) || requestModel.PageIndex <= 0 || requestModel.PageSize <= 0) { response.IsSuccess = false; response.MessageCode = (int)ApiBaseErrorCode.API_PARAM_ERROR; response.MessageContent = "必要参数格式不对,请检查"; return(Ok(response)); } try { CardServiceSearchModel searchModel = new CardServiceSearchModel(); searchModel.PageIndex = requestModel.PageIndex; searchModel.PageSize = requestModel.PageSize; searchModel.ProjectGuid = requestModel.ProjectGuid; searchModel.ParkingCode = requestModel.ParkingCode; searchModel.CarNo = requestModel.CarNo;; searchModel.CarOwnerName = requestModel.CarOwnerName; searchModel.Mobile = requestModel.Mobile; searchModel.StartDate = requestModel.ApplyDate; searchModel.CarTypeGuid = requestModel.CarTypeGuid; int statusType = requestModel.StatusType; if (statusType == 1) { searchModel.Enable = true; searchModel.Locked = false; } else if (statusType == 3) { searchModel.Locked = true; } List <CardServiceModel> list = _cardServiceManager.GetTempCardPage(searchModel); response.Result = list; response.TotalCount = searchModel.TotalCount; } catch (Exception ex) { response.IsSuccess = false; response.MessageCode = (int)ApiBaseErrorCode.API_FAIL; response.MessageContent = "请检查参数格式是否符合"; } return(Ok(response)); }
public IList <CardServiceModel> GetFromDataBaseByPage <T>(T model) { CardServiceSearchModel searchModel = model as CardServiceSearchModel; List <CardServiceModel> list = null; MysqlHelper dbhelper = new MysqlHelper("name=parklotManager", "MySql.Data.MySqlClient"); DataTable table = new DataTable(); //临时卡表查询cmd string cmdText = " SELECT * FROM t_tempcard INNER JOIN (SELECT id FROM t_tempcard {0}" + $" ORDER BY id DESC LIMIT {(searchModel.PageIndex - 1) * searchModel.PageSize},{searchModel.PageSize}) AS page USING(id); "; //查询条件cmd string whereText = $" WHERE projectGuid = '{searchModel.ProjectGuid}' and parkCode = '{searchModel.ParkingCode}' "; if (!string.IsNullOrEmpty(searchModel.CarNo)) { whereText += $" and instr(carNo,'{searchModel.CarNo}')> 0 "; } if (!string.IsNullOrEmpty(searchModel.Mobile)) { whereText += $" and mobile = '{searchModel.Mobile}' "; } if (!string.IsNullOrEmpty(searchModel.CarOwnerName)) { whereText += $" and carOwnerName = '{searchModel.CarOwnerName}' "; } if (searchModel.StartDate != null && searchModel.StartDate != DateTime.MinValue) { whereText += $" and DATE_FORMAT(startDate,'%Y-%m-%d') = '{searchModel.StartDate.Value.ToString("yyyy-MM-dd")}' "; } if (searchModel.Locked != null) { whereText += $" and locked = {(searchModel.Locked.Value ? 1 : 0)} "; } if (!string.IsNullOrEmpty(searchModel.CarTypeGuid)) { whereText += $" and carTypeGuid = '{searchModel.CarTypeGuid}' "; } cmdText = string.Format(cmdText, whereText); //总条数cmd string cmdTextCount = "SELECT COUNT(*) FROM t_tempcard " + whereText; long count = (long)dbhelper.ExecuteScalar(cmdTextCount); if (count <= 0) { return(list); } searchModel.TotalCount = count; table = dbhelper.ExecuteDataTable(cmdText); if (table == null || table.Rows.Count <= 0) { return(list); } list = new List <CardServiceModel>(); foreach (DataRow item in table.Rows) { CardServiceModel csm = new CardServiceModel() { ProjectGuid = (string)item["projectGuid"], ParkCode = (string)item["parkCode"], CarNo = (string)item["carNo"], CarOwnerName = (string)item["carOwnerName"], Mobile = (string)item["mobile"], DrivewayGuidList = m_serializer.Deserialize <List <string> >(item["drivewayListContent"].ToString()), CarTypeGuid = (string)item["carTypeGuid"], Remark = item["remark"].ToString(), Enable = (item["enable"].ToString() == "0" ? false : true), Locked = (item["locked"].ToString() == "0" ? false : true), Balance = 0, RechargeOperator = item["rechargeOperator"].ToString() }; if (!string.IsNullOrWhiteSpace(item["startDate"].ToString())) { csm.StartDate = DateTime.Parse(item["startDate"].ToString()); } if (!string.IsNullOrWhiteSpace(item["endDate"].ToString())) { csm.EndDate = DateTime.Parse(item["endDate"].ToString()); } if (!string.IsNullOrWhiteSpace(item["pauseDate"].ToString())) { csm.PauseDate = DateTime.Parse(item["pauseDate"].ToString()); } if (!string.IsNullOrWhiteSpace(item["continueDate"].ToString())) { csm.ContinueDate = DateTime.Parse(item["continueDate"].ToString()); } list.Add(csm); } table.Clear(); return(list); }