using Sugar.Enties;
using SqlSugar;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;
using WebAPIBase.Utils;
public class SafeQualityCheckManager : DbContext<SafeQualityCheck>
{

    //当前类已经继承了 DbContext增、删、查、改的方法

    //这里面写的代码不会给覆盖,如果要重新生成请删除 SafeQualityCheckManager.cs


    /// <summary>
    /// 质量安全检查列表获取
    /// </summary>
    /// <param name="checkType">检查类型</param>
    /// <param name="searchValue">搜索条件</param>
    /// <returns></returns>
    public List<SafeQualityCheckDTO> GetSafeQualityCheckDTOs(string checkType, string searchValue)
    {

        List<SafeQualityCheckDTO> list;
        var sql = $"select * from SafeQualityCheck where 1=1";
        if (searchValue.IsNullOrEmpty())
        {
            sql += $" and checktype='{checkType}' order by checktype desc";
            list = Db.Ado.SqlQuery<SafeQualityCheckDTO>(sql);
        }
        else
        {
            sql += $" and checktype='{checkType}' and projectname like '%{searchValue}%' order by checktype desc";
            list = Db.Ado.SqlQuery<SafeQualityCheckDTO>(sql);
        }
        return list;
    }

    /// <summary>
    /// 获取质量安全检查实例通过主键
    /// </summary>
    /// <param name="checkCode"></param>
    /// <returns></returns>
    public SafeQualityCheckDTO GetSafeQualityCheckDTO(string checkCode)
    {
        var sql = $"select * from SafeQualityCheck where checkcode='{checkCode}'";
        var entity = Db.Ado.SqlQuerySingle<SafeQualityCheckDTO>(sql);
        return entity;
    }

    /// <summary>
    /// 获取质量安全明细列表
    /// </summary>
    /// <param name="checkCode"></param>
    /// <returns></returns>
    public List<SafeQualityCheckItem> GetSafeQualityCheckItems(string checkCode)
    {
        var sql = $"select * from SafeQualityCheckItem where checkcode='{checkCode}'";
        var list = Db.Ado.SqlQuery<SafeQualityCheckItem>(sql);
        return list;
    }


}
