public Task <GetCommentResponseDto> GetCommentListAsync(GetCommentRequestDto dto) { return(Task.Run(() => { List <CommentListModel> list = new List <CommentListModel>(); int total = 0; Guid qId = Guid.Empty; string qTitle = ""; if (!string.IsNullOrEmpty(dto.q)) { if (!Guid.TryParse(dto.q, out qId)) { qTitle = dto.q; } } string worksSql; string productSql; string worksCountSql; string productCountSql; switch (dto.target_type) { #region all //case TargetTypeEnum.All: // worksSql = string.Format(CommentServiceConst.SELECT_WORKS_COMMENT_LIST, // qId.Equals(Guid.Empty) ? "" : CommentServiceConst.SELECT_WORKS_COMMENT_WHERE_0, // string.IsNullOrEmpty(qTitle) ? "" : CommentServiceConst.SELECT_WORKS_COMMENT_WHERE_1); // list = _dapperRepository.Query<CommentListModel>(worksSql, new // { // start = dto.start, // length = (dto.length / 2), // worksId = qId.Equals(Guid.Empty) ? "" : dto.q, // title = string.IsNullOrEmpty(qTitle) ? "" : dto.q // }).ToList(); // productSql = string.Format(CommentServiceConst.SELECT_PRODUCT_COMMENT_LIST, // qId.Equals(Guid.Empty) ? "" : CommentServiceConst.SELECT_PRODUCT_COMMENT_WHERE_0, // string.IsNullOrEmpty(qTitle) ? "" : CommentServiceConst.SELECT_PRODUCT_COMMENT_WHERE_1); // list.AddRange(_dapperRepository.Query<CommentListModel>(productSql, // new // { // start = dto.start, // length = dto.length - list.Count, // worksId = qId.Equals(Guid.Empty) ? "" : dto.q, // title = string.IsNullOrEmpty(qTitle) ? "" : dto.q // }).ToList()); // if (string.IsNullOrEmpty(dto.q)) // { // total = _dapperRepository.ExecuteScalar<int>(CommentServiceConst.QUERY_ALL_COMMENT_COUNT); // } // else // { // worksCountSql = string.Format(CommentServiceConst.QUERY_WORKS_COMMENT_COUNT, // qId.Equals(Guid.Empty) ? "" : CommentServiceConst.SELECT_WORKS_COMMENT_WHERE_0, // string.IsNullOrEmpty(qTitle) ? "" : CommentServiceConst.SELECT_WORKS_COMMENT_WHERE_1); // productCountSql = string.Format(CommentServiceConst.QUERY_PRODUCT_COMMENT_COUNT, // qId.Equals(Guid.Empty) ? "" : CommentServiceConst.SELECT_PRODUCT_COMMENT_WHERE_0, // string.IsNullOrEmpty(qTitle) ? "" : CommentServiceConst.SELECT_PRODUCT_COMMENT_WHERE_1); // total = _dapperRepository.ExecuteScalar<int>(worksCountSql) + _dapperRepository.ExecuteScalar<int>(productCountSql); // } // break; #endregion case TargetTypeEnum.Works: worksSql = string.Format(CommentServiceConst.SELECT_WORKS_COMMENT_LIST, qId.Equals(Guid.Empty) ? "" : CommentServiceConst.SELECT_WORKS_COMMENT_WHERE_0, string.IsNullOrEmpty(qTitle) ? "" : CommentServiceConst.SELECT_WORKS_COMMENT_WHERE_1); list = _dapperRepository.Query <CommentListModel>(worksSql, new { start = dto.start, length = dto.length, worksId = qId.Equals(Guid.Empty) ? "" : dto.q, title = string.IsNullOrEmpty(qTitle) ? "" : "%" + dto.q + "%" }).ToList(); worksCountSql = string.Format(CommentServiceConst.QUERY_WORKS_COMMENT_COUNT, qId.Equals(Guid.Empty) ? "" : CommentServiceConst.SELECT_WORKS_COMMENT_WHERE_0, string.IsNullOrEmpty(qTitle) ? "" : CommentServiceConst.SELECT_WORKS_COMMENT_WHERE_1); total = _dapperRepository.ExecuteScalar <int>(worksCountSql, new { worksId = qId.Equals(Guid.Empty) ? "" : dto.q, title = string.IsNullOrEmpty(qTitle) ? "" : "%" + dto.q + "%" }); break; case TargetTypeEnum.Product: productSql = string.Format(CommentServiceConst.SELECT_PRODUCT_COMMENT_LIST, qId.Equals(Guid.Empty) ? "" : CommentServiceConst.SELECT_PRODUCT_COMMENT_WHERE_0, string.IsNullOrEmpty(qTitle) ? "" : CommentServiceConst.SELECT_PRODUCT_COMMENT_WHERE_1); list = _dapperRepository.Query <CommentListModel>(productSql, new { start = dto.start, length = dto.length, worksId = qId.Equals(Guid.Empty) ? "" : dto.q, title = string.IsNullOrEmpty(qTitle) ? "" : "%" + dto.q + "%" }).ToList(); productCountSql = string.Format(CommentServiceConst.QUERY_PRODUCT_COMMENT_COUNT, qId.Equals(Guid.Empty) ? "" : CommentServiceConst.SELECT_PRODUCT_COMMENT_WHERE_0, string.IsNullOrEmpty(qTitle) ? "" : CommentServiceConst.SELECT_PRODUCT_COMMENT_WHERE_1); total = _dapperRepository.ExecuteScalar <int>(productCountSql, new { worksId = qId.Equals(Guid.Empty) ? "" : dto.q, title = string.IsNullOrEmpty(qTitle) ? "" : "%" + dto.q + "%" }); break; default: throw new RequestErrorException("类型错误"); } GetCommentResponseDto resp = new GetCommentResponseDto(); resp.data = Mapper.Map <List <CommentDto> >(list); resp.total = total; return resp; })); }