using Sugar.Enties;
using SqlSugar;
using System;
using System.Collections.Generic;
using WebAPIBase.Utils;
/// <summary>
/// 待审签证管理类
/// </summary>
public class ViseManager : DbContext<Vise>
{

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

    //这里面写的代码不会给覆盖,如果要重新生成请删除 ViseManager.cs
    /// <summary>
    /// 获取待审签证列表
    /// </summary>
    /// <param name="projectCode"></param>
    /// <param name="searchValue"></param>
    /// <returns></returns>
    public List<ViseDTO> GetVises(string projectCode, string searchValue = "")
    {
        var sql = $"SELECT v.ViseCode,v.ViseId,v.ViseName,v.ViseType,CONVERT(VARCHAR(10),v.ViseDate,120) ViseDate,v.State,dbo.GetUnitFullName(v.UnitCode) unitFullName, c.ContractName,v.ContractCode from Vise v INNER JOIN dbo.Contract c ON v.ContractCode=c.ContractCode where (dbo.GetUnitFullCode(v.UnitCode) like ('100000%')) and v.ProjectCode = '{projectCode}' and v.State ='0'  ";
        if (searchValue.IsNotNullAndEmpty())
        {
            sql += $" and (v.ViseId='{searchValue}' or v.ViseName like '%{searchValue}%')";
        }
        sql += "  order by v.ViseCode desc";
        var list = Db.Ado.SqlQuery<ViseDTO>(sql);
        return list;
    }
    /// <summary>
    /// 根据签证编码获取待审签证实例
    /// </summary>
    /// <param name="viseCode"></param>
    /// <returns></returns>
    public ViseDTO GetVise(string viseCode)
    {
        var sql = $"SELECT v.*,dbo.GetUnitFullName(v.UnitCode) unitFullName, c.ContractName from Vise v INNER JOIN dbo.Contract c ON v.ContractCode=c.ContractCode where  v.viseCode = '{viseCode}'  ";

        var entity = Db.Ado.SqlQuerySingle<ViseDTO>(sql);
        return entity;
    }
    /// <summary>
    /// 待审核签证费用明细
    /// </summary>
    /// <param name="viseCode"></param>
    /// <returns></returns>
    public List<ViseCostDTO> GetViseCostDTOs(string viseCode)
    {
        var sql = $"SELECT *  FROM visecost  WHERE ViseCode='{viseCode}'";
        var list = Db.Ado.SqlQuery<ViseCostDTO>(sql);
        return list;
    }


}
