QrCodeListService.cs 2.52 KB
using Hh.Mes.Common.log;
using Hh.Mes.Pojo.System;
using Hh.Mes.POJO.Entity;
using Hh.Mes.POJO.Response;
using Hh.Mes.Service.Repository;
using System;
using System.Collections.Generic;
using System.Text;

namespace Hh.Mes.Service
{
    public class QrCodeListService : RepositorySqlSugar<QrCodeList>
    {
        /// <summary>
        /// 读取数据
        /// </summary>
        public dynamic ReadData(string id)
        {
            var response = new Response();
            return ExceptionsHelp.Instance.ExecuteT(() =>
            {
                List<QrCodeList> qrCodeLists = new List<QrCodeList>();
                if (!string.IsNullOrEmpty(id))
                {
                    var qrCodeList = this.GetById(id);
                    qrCodeLists.Add(qrCodeList);
                } else
                {
                    qrCodeLists = this.GetList();
                }

                response.Result = new
                {
                    qrCodeLists
                };
                return response;
            });
        }

        /// <summary>
        /// 保存数据
        /// </summary>
        public dynamic SaveData(QrCodeList qrCodeList)
        {
            var response = new Response();
            return ExceptionsHelp.Instance.ExecuteT(() =>
            {
                bool success = false;
                if (qrCodeList.id == 0)
                {
                    qrCodeList.createTime = DateTime.Now;
                    success = this.Insert(qrCodeList);
                }
                else
                {
                    qrCodeList.updateTime = DateTime.Now;
                    success = this.Update(qrCodeList);
                }

                if (success)
                {
                    response.ResponseSuccess();
                }
                else
                {
                    response.ResponseError();
                }
                
                return response;
            });
        }

        /// <summary>
        /// 删除数据
        /// </summary>
        public dynamic DelData(string id)
        {
            var response = new Response();
            return ExceptionsHelp.Instance.ExecuteT(() =>
            {
                bool success = this.DeleteById(id);
                if (success)
                {
                    response.ResponseSuccess();
                }
                else
                {
                    response.ResponseError();
                }

                return response;
            });
        }
    }
}