You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
DS7/DSWeb/Areas/MvcShipping/Models/BIReport/BIReportModel.cs

250 lines
7.6 KiB
C#

1 year ago
using System;
using HcUtility.Core;
using Newtonsoft.Json;
using System.Collections.Generic;
using System.Text;
using DSWeb.Areas.CommMng.DAL;
using DSWeb.MvcShipping.DAL.MsCodeOpDef;
using DSWeb.EntityDA;
using Microsoft.Owin;
using NPOI.SS.Formula.Functions;
namespace DSWeb.MvcShipping.Models.BIReport
{
/// <summary>
/// BI报表 业务和利润
/// </summary>
[JsonObject]//
public class BIREPORT_BILLmb : ModelObjectBillHead
{
public override Dictionary<string, ModelDBOprationType> GetPKey()
{//用于给扩展的动态数据提供主键字段名
var d = new Dictionary<string, ModelDBOprationType>() { { "Id", ModelDBOprationType.All } };
return d;
}
public Dictionary<string, string> SaveDic = new Dictionary<string, string>();
private static string getBaseSql() {
return @" SELECT * from BIREPORT_BILL where 1=1 ";
}
/// <summary>
/// 获取查询语句 含权限和分页
/// </summary>
/// <param name="start"></param>
/// <param name="limit"></param>
/// <param name="strCondition"></param>
/// <param name="sortstring"></param>
/// <returns></returns>
public string getSQL(int start, int limit,string strCondition, string userid, out int count, string sortstring="")
{
var rangestr = "";
if(!(start==0 && limit==1))
rangestr = BasicDataRefDAL.GetRangeCondition(BasicDataRefDAL.RangeType.Visable, "modOp_InternalTrade", userid, GetCompanyFieldName(),new string[] { "OP", "CUSTSERVICE", "SALE" });
var param = new BasicDataRefDAL.PagedQuaryParam();
param.strSql = getBaseSql();
param.strCondition = strCondition;
param.rangestr = rangestr;
param.sortstring = sortstring;
param.defaultsortstr = "ETD desc";
param.start = start;
param.limit = limit;
var result = BasicDataRefDAL.PagedQuaryStr(param);
count = BasicDataRefDAL.PagedCount(param);
return result.ToString();
}
public string getSumSql(int start, int limit, string strCondition, out int count, List<string>GroupField, List<string> SumField,string sort="")
{
var param = new BasicDataRefDAL.PagedQuaryParam();
param.strSql = getSumSqlStr(GroupField, SumField, strCondition);
param.strCondition = "";
param.rangestr = "";
param.sortstring = sort;
param.defaultsortstr = "";
param.start = start;
param.limit = limit;
var result = BasicDataRefDAL.PagedQuaryStr(param);
count = BasicDataRefDAL.PagedCount(param);
return result.ToString();
}
private string getSumSqlStr(List<string> GroupField, List<string> SumField,string strCondition) {
if (GroupField == null || GroupField == null || GroupField.Count == 0 || GroupField.Count == 0)
{
return "select Id=1";
}
var result = "";
var selectfield = string.Join(",", GroupField);
var sumfield = "";
foreach (var item in SumField)
{
if (sumfield != "") sumfield += ",";
sumfield += $"sum(isnull({item},0))as {item}";
}
if (!string.IsNullOrWhiteSpace(strCondition))
{
strCondition = " and " + strCondition;
}
else {
strCondition = "";
}
result = $"select { selectfield },{ sumfield } from BIREPORT_BILL where 1=1 {strCondition} group by {selectfield} ";
return result;
}
public BIREPORT_BILLmb()
{
TableName = "BIREPORT_BILL";
}
public override string GetBillNoFieldName()
{
return "Id";
}
//public override string GetTimeMarkFieldName()
//{
// return "TIMEMARK";
//}
}
/// <summary>
/// BI报表 欠费
/// </summary>
[JsonObject]//
public class BIREPORT_NODRCRmb : ModelObjectBillHead
{
public override Dictionary<string, ModelDBOprationType> GetPKey()
{//用于给扩展的动态数据提供主键字段名
var d = new Dictionary<string, ModelDBOprationType>() { { "Id", ModelDBOprationType.All } };
return d;
}
public Dictionary<string, string> SaveDic = new Dictionary<string, string>();
private static string getBaseSql()
{
return @" SELECT * from BIREPORT_NODRCR where 1=1 ";
}
/// <summary>
/// 获取查询语句 含权限和分页
/// </summary>
/// <param name="start"></param>
/// <param name="limit"></param>
/// <param name="strCondition"></param>
/// <param name="sortstring"></param>
/// <returns></returns>
public string getSQL(int start, int limit, string strCondition, string userid, out int count, string sortstring = "")
{
var rangestr = "";
if (!(start == 0 && limit == 1))
rangestr = BasicDataRefDAL.GetRangeCondition(BasicDataRefDAL.RangeType.Visable, "modOp_InternalTrade", userid, GetCompanyFieldName(), new string[] { "OP", "CUSTSERVICE", "SALE" });
var param = new BasicDataRefDAL.PagedQuaryParam();
param.strSql = getBaseSql();
param.strCondition = strCondition;
param.rangestr = rangestr;
param.sortstring = sortstring;
param.defaultsortstr = "ETD desc";
param.start = start;
param.limit = limit;
var result = BasicDataRefDAL.PagedQuaryStr(param);
count = BasicDataRefDAL.PagedCount(param);
return result.ToString();
}
public string getSumSql(int start, int limit, string strCondition, out int count, List<string> GroupField, List<string> SumField)
{
var param = new BasicDataRefDAL.PagedQuaryParam();
param.strSql = getSumSqlStr(GroupField, SumField);
param.strCondition = strCondition;
param.rangestr = "";
param.sortstring = "";
param.defaultsortstr = "";
param.start = start;
param.limit = limit;
var result = BasicDataRefDAL.PagedQuaryStr(param);
count = BasicDataRefDAL.PagedCount(param);
return result.ToString();
}
private string getSumSqlStr(List<string> GroupField, List<string> SumField)
{
if (GroupField == null || GroupField == null || GroupField.Count == 0 || GroupField.Count == 0)
{
return "select Id=1";
}
var result = "";
var selectfield = string.Join(",", GroupField);
var sumfield = "";
foreach (var item in SumField)
{
if (sumfield != "") sumfield += ",";
sumfield += $"sum(isnull({item},0))as {item}";
}
result = $"select {selectfield},{sumfield} from BIREPORT_NODRCR group by {selectfield} where 1=1 ";
return result;
}
public BIREPORT_NODRCRmb()
{
TableName = "BIREPORT_NODRCR";
}
public override string GetBillNoFieldName()
{
return "Id";
}
//public override string GetTimeMarkFieldName()
//{
// return "TIMEMARK";
//}
}
}