using com.hnshituo.core.webapp.vo;
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Common
{
    public class ComBaseInfoService
    {
        /// <summary>
        /// 基础信息查询，转换为PbModelDb
        /// </summary>
        /// <param name="info"></param>
        /// <returns></returns>
        public RESTfulResult<List<PbModelDb>> doQueryWf(ComBaseInfo info)
        {
            DbHelper db = new DbHelper();
            RESTfulResult<PageList<List<ComBaseInfo>>> rm = db.doOption<PageList<List<ComBaseInfo>>>("combaseinfos", "/", new object[] { info }, 0);

            RESTfulResult<List<PbModelDb>> result = new RESTfulResult<List<PbModelDb>>();
            result.Succeed = rm.Succeed;
            result.Status = rm.Status;
            result.Message = rm.Message;
            result.ResultMessage = rm.ResultMessage;
            result.Code = rm.Code;
            if (rm.Data != null && rm.Data.list != null && rm.Data.list.Count > 0)
            {
                List<PbModelDb> lpb = new List<PbModelDb>();
                foreach (ComBaseInfo cbi in rm.Data.list) 
                {
                    PbModelDb pb = new PbModelDb();
                    pb.id = cbi.baseCode;
                    pb.text = cbi.baseName;
                    lpb.Add(pb);
                }
                result.Data = lpb;
            }

            return result;
        }

        /// <summary>
        /// 基础信息查询，保持ComBaseInfo
        /// </summary>
        /// <param name="info"></param>
        /// <returns></returns>
        public RESTfulResult<List<ComBaseInfo>> doQueryBaseList(ComBaseInfo info)
        {
            DbHelper db = new DbHelper();
            RESTfulResult<PageList<List<ComBaseInfo>>> rm = db.doOption<PageList<List<ComBaseInfo>>>("combaseinfos", "/", new object[] { info }, 0);

            RESTfulResult<List<ComBaseInfo>> result = new RESTfulResult<List<ComBaseInfo>>();
            result.Succeed = rm.Succeed;
            result.Status = rm.Status;
            result.Message = rm.Message;
            result.ResultMessage = rm.ResultMessage;
            result.Code = rm.Code;
            if (rm.Succeed && rm.Data != null && rm.Data.list.Count > 0)
            {
                result.Data = rm.Data.list;
            }
            return result;
        }

        /// <summary>
        /// 客户端更新数据
        /// </summary>
        /// <param name="lt"></param>
        /// <returns></returns>
        public RESTfulResult<string> doUpdateWf(ComBaseInfo model)
        {
            DbHelper db = new DbHelper();
            RESTfulResult<string> rm = db.doOption<string>("combaseinfos", "doUpdateWf", new object[] { model }, 1);
            return rm;
        }
    }
}
