using System; using System.Linq; using System.Text; using System.Data.Common; using System.Linq.Expressions; using System.Collections.Generic; using System.Threading.Tasks; using YiSha.Util; using YiSha.Util.Extension; using YiSha.Util.Model; using YiSha.Data; using YiSha.Data.Repository; using YiSha.Enum; using System.ComponentModel.DataAnnotations.Schema; using YiSha.Entity.TK; using YiSha.Model.Param.TK; using YiSha.IService.TK; using YiSha.Model.Result.TK; using YiSha.Web.Code; namespace YiSha.Service.TK { /// /// 创 建:cmzx /// 日 期:2021-04-21 15:55 /// 描 述:图库图片信息表服务实现类(部分类) /// public partial class ImageManagerModelsService { private IRepositoryFactory _baseRepository; public ImageManagerModelsService(IRepositoryFactory baseRepository) { _baseRepository = baseRepository; } /// /// 获取分页数据 /// /// 请求参数 /// 分页条件 /// public async Task> GetPageListPartial(ImageManagerModelsListParam param, Pagination pagination) { var parameters = new List(); var sql = SqlPageList(param, pagination, out parameters); var list = await _baseRepository.BaseRepository(dbConnectType).FindList(sql, parameters.ToArray()); return list.ToList(); } /// /// 保存数据(由于之前数据库设计不规范,无法实现在新增、修改时保存正确的操作用户信息,每张表的创建时间和创建人id、创建人姓名都不一样,且这些字段是必填项) /// /// 实体参数 /// public async Task SaveFormPartial(ImageManagerModelsEntity entity) { OperatorInfo user = await Operator.Instance.Current(entity.Token); if (entity.Id.IsNullOrZero()) { entity.createTime = DateTime.Now; entity.createUserId = user?.UserId; entity.createUserName = user?.UserName; entity.Years = DateTime.Now.Year.ToString(); entity.updateTime = DateTime.Now; return await _baseRepository.BaseRepository(dbConnectType).Insert(entity); } else { return await _baseRepository.BaseRepository(dbConnectType).Update(entity); } } /// /// 获取最后一期 期数 /// /// /// public async Task GetLastQi(int Year) { var sql = @"select top 1 periodsNumber from ImageManagerModels where Years = @Year and isDelete = 0 order by periodsNumber desc;"; var param = new List(); param.Add(DbParameterExtension.CreateDbParameter("@Year", Year, dbConnectType)); var list = await _baseRepository.BaseRepository(dbConnectType).FindList(sql, param.ToArray()); return list.FirstOrDefault()?.periodsNumber; } #region 私有方法 /// /// 列表条件过滤 /// 建议该方法放在Partial部分类中,因为代码生成时当前类会被覆盖(该方法在生成时将会被注释) /// /// /// private Expression> ListFilterPartial(ImageManagerModelsListParam param) { var expression = LinqExtensions.True(); if (param != null) { } return expression; } /// /// 获取分页Sql语句 /// /// /// private string SqlPageList(ImageManagerModelsListParam param, Pagination pagination, out List parameters) { parameters = new List(); var where = new StringBuilder(); where.Append(" 1 = 1 "); if (param != null) { if (!string.IsNullOrEmpty(param.GalleryName)) { where.Append(" and gal.GalleryName like @GalleryName "); parameters.Add(DbParameterExtension.CreateDbParameter("@GalleryName", $"%{param.GalleryName}%", dbConnectType)); } if (!param.PeriodsNumber.IsNullOrZero()) { where.Append(" and img.periodsNumber = @PeriodsNumber "); parameters.Add(DbParameterExtension.CreateDbParameter("@PeriodsNumber", param.PeriodsNumber, dbConnectType)); } if (!string.IsNullOrEmpty(param.CreateUserName)) { where.Append(" and img.createUserName = @CreateUserName "); parameters.Add(DbParameterExtension.CreateDbParameter("@CreateUserName", param.CreateUserName, dbConnectType)); } } //获取分页数据Sql var pageSql = $@"select img.Id, img.periodsNumber, img.Years, img.createTime, img.createUserName, gal.galleryNumber, gal.galleryName, gal.isPicZip from ImageManagerModels img left join galleryManagerModels gal on img.galleryId = gal.ID where {where.ToString()}"; //统计总数据Sql var totalSql = $@"select count(1) from ImageManagerModels img left join galleryManagerModels gal on img.galleryId = gal.ID where {where.ToString()}"; pageSql = SqlserverHelper.GetInstance.SqlPageList(pageSql, totalSql, pagination); return pageSql; } #endregion } }