327 lines
12 KiB
C#
327 lines
12 KiB
C#
using FineUIPro;
|
|
using Model;
|
|
using Newtonsoft.Json;
|
|
using System;
|
|
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using Newtonsoft.Json.Linq;
|
|
using System.Net.PeerToPeer;
|
|
|
|
namespace BLL
|
|
{
|
|
public static class HJGLData_HJGLService
|
|
{
|
|
public static SGGLDB db = Funs.DB;
|
|
|
|
#region 获取列表
|
|
|
|
/// <summary>
|
|
/// 记录数
|
|
/// </summary>
|
|
public static int count { get; set; }
|
|
|
|
public static List<HJGLData_HJGL> GetHJGLData_HJGLByModle(HJGLData_HJGL table)
|
|
{
|
|
var db = Funs.DB;
|
|
var q = from x in db.HJGLData_HJGL
|
|
where
|
|
(string.IsNullOrEmpty(table.Id) || x.Id.Contains(table.Id)) &&
|
|
(string.IsNullOrEmpty(table.UnitId) || x.UnitId.Contains(table.UnitId)) &&
|
|
(string.IsNullOrEmpty(table.CollCropCode) || x.CollCropCode.Contains(table.CollCropCode)) &&
|
|
(string.IsNullOrEmpty(table.UnitName) || x.UnitName.Contains(table.UnitName))
|
|
orderby x.ReportDate descending
|
|
select x
|
|
;
|
|
|
|
return q.ToList();
|
|
}
|
|
|
|
/// 获取分页列表
|
|
/// </summary>
|
|
/// <param name="PageIndex">页码</param>
|
|
/// <param name="PageSize">每页数量</param>
|
|
/// <returns></returns>
|
|
public static IEnumerable getListData(HJGLData_HJGL table, Grid Grid1)
|
|
{
|
|
var q = GetHJGLData_HJGLByModle(table);
|
|
count = q.Count();
|
|
if (count == 0) return null;
|
|
// q = SortConditionHelper.SortingAndPaging(q, Grid1.SortField, Grid1.SortDirection, Grid1.PageIndex, Grid1.PageSize);
|
|
return from x in q
|
|
select new
|
|
{
|
|
x.Id,
|
|
x.UnitId,
|
|
x.CollCropCode,
|
|
x.UnitName,
|
|
x.ReportDate,
|
|
x.WelderNum,
|
|
x.TotalDineNum,
|
|
x.CompleteDineNum,
|
|
x.TotalFilmNum,
|
|
x.OKFilmNum,
|
|
x.State,
|
|
x.CreateDate,
|
|
x.CreateMan
|
|
};
|
|
}
|
|
|
|
#endregion 获取列表
|
|
|
|
public static void AddHJGLData_HJGL(HJGLData_HJGL newtable)
|
|
{
|
|
using (Model.SGGLDB db = new Model.SGGLDB(Funs.ConnString))
|
|
{
|
|
var table = new HJGLData_HJGL
|
|
{
|
|
Id = newtable.Id,
|
|
UnitId = newtable.UnitId,
|
|
CollCropCode = newtable.CollCropCode,
|
|
UnitName = newtable.UnitName,
|
|
ReportDate = newtable.ReportDate,
|
|
WelderNum = newtable.WelderNum,
|
|
TotalDineNum = newtable.TotalDineNum,
|
|
CompleteDineNum = newtable.CompleteDineNum,
|
|
TotalFilmNum = newtable.TotalFilmNum,
|
|
OKFilmNum = newtable.OKFilmNum,
|
|
State = newtable.State,
|
|
CreateDate = newtable.CreateDate,
|
|
CreateMan = newtable.CreateMan
|
|
};
|
|
db.HJGLData_HJGL.InsertOnSubmit(table);
|
|
db.SubmitChanges();
|
|
}
|
|
|
|
}
|
|
|
|
public static void DeleteHJGLData_HJGLById(string Id)
|
|
{
|
|
using (Model.SGGLDB db = new Model.SGGLDB(Funs.ConnString))
|
|
{
|
|
var table = db.HJGLData_HJGL.FirstOrDefault(x => x.Id == Id);
|
|
if (table != null)
|
|
{
|
|
db.HJGLData_HJGL.DeleteOnSubmit(table);
|
|
db.SubmitChanges();
|
|
}
|
|
}
|
|
|
|
}
|
|
|
|
public static HJGLData_HJGL GetHJGLData_HJGLById(string Id)
|
|
{
|
|
var db = Funs.DB;
|
|
return db.HJGLData_HJGL.FirstOrDefault(x => x.Id == Id);
|
|
}
|
|
|
|
public static HJGLData GetItemById(string Id)
|
|
{
|
|
var item = new HJGLDataItem();
|
|
var data = new HJGLData();
|
|
var data_HJGL = GetHJGLData_HJGLById(Id);
|
|
if (data_HJGL != null)
|
|
{
|
|
var data_HJGL_detail = HJGLData_DefectService.GetHJGLData_DefectByDate(data_HJGL.ReportDate);
|
|
|
|
item.CollCropCode = data_HJGL.CollCropCode;
|
|
item.CompleteDineNum = data_HJGL.CompleteDineNum;
|
|
item.Id = data_HJGL.Id;
|
|
item.OKFilmNum = data_HJGL.OKFilmNum;
|
|
item.ReportDate = data_HJGL.ReportDate.Value.ToShortDateString();
|
|
item.TotalDineNum = data_HJGL.TotalDineNum;
|
|
item.TotalFilmNum = data_HJGL.TotalFilmNum;
|
|
item.UnitId = data_HJGL.UnitId;
|
|
item.WelderNum = data_HJGL.WelderNum;
|
|
var list = new List<HJGLDataDefectItems>();
|
|
if (data_HJGL_detail != null)
|
|
{
|
|
foreach (var detail in data_HJGL_detail)
|
|
{
|
|
var hjglDataDefectItem = new HJGLDataDefectItems();
|
|
hjglDataDefectItem.DefectNum = detail.DefectNum;
|
|
hjglDataDefectItem.DefectName = detail.DefectName;
|
|
hjglDataDefectItem.Id = detail.Id;
|
|
list.Add(hjglDataDefectItem);
|
|
}
|
|
|
|
item.HJGLDataDefectItems = list;
|
|
}
|
|
}
|
|
|
|
var hJGLDataItems = new List<HJGLDataItem>();
|
|
hJGLDataItems.Add(item);
|
|
data.HJGLDataItems = hJGLDataItems;
|
|
return data;
|
|
}
|
|
|
|
public static HJGLData GetTodayHJGLData_HJGL()
|
|
{
|
|
var data = new HJGLData();
|
|
if (CommonService.GetIsThisUnit().CollCropCode== "91410200170644116B")
|
|
{
|
|
return GetELECLTodayHJGLData_HJGL();
|
|
}
|
|
var q = GetTodayData();
|
|
if (q != null && q.State == Const.CNCEC_State_S)
|
|
data = StatisticalData();
|
|
else
|
|
data = StatisticalData();
|
|
return data;
|
|
}
|
|
/// <summary>
|
|
/// 获取十一化建焊接数据
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
public static HJGLData GetELECLTodayHJGLData_HJGL()
|
|
{
|
|
var data = new HJGLData();
|
|
string baseurl = "http://36.99.162.230:9493/sgglapi/api/CNCECServer/PostGetHJGLData";
|
|
string token = Const.sysglyId;
|
|
string response = Funs.RequestPost(baseurl, token, "");
|
|
var json = JsonConvert.DeserializeObject(response) as JObject;
|
|
if (json != null && json["code"]?.ToString()=="1")
|
|
{
|
|
var str = json["data"]?.ToString();
|
|
if (str != null) data = JsonConvert.DeserializeObject<HJGLData>(str);
|
|
}
|
|
return data;
|
|
|
|
}
|
|
public static HJGLData_HJGL GetTodayData()
|
|
{
|
|
var q = (from x in Funs.DB.HJGLData_HJGL
|
|
where x.ReportDate < DateTime.Now.AddDays(1).Date && x.ReportDate >= DateTime.Now.Date
|
|
select x).FirstOrDefault();
|
|
return q;
|
|
}
|
|
|
|
public static void UpdateTodyData_State()
|
|
{
|
|
var q = GetTodayData();
|
|
if (q != null)
|
|
{
|
|
q.State = Const.CNCEC_State_1;
|
|
UpdateHJGLData_HJGL(q);
|
|
}
|
|
}
|
|
|
|
public static bool IsReportByDate(DateTime dateTime)
|
|
{
|
|
var result = false;
|
|
var q = (from x in Funs.DB.HJGLData_HJGL
|
|
where x.ReportDate >= dateTime.Date && x.ReportDate < dateTime.Date.AddDays(1).Date
|
|
select x).ToList();
|
|
if (q != null && q.Count > 0) result = true;
|
|
return result;
|
|
}
|
|
|
|
/// <summary>
|
|
/// 判断当天是否已上报
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
public static bool IsReportByToday()
|
|
{
|
|
var result = false;
|
|
var q = (from x in Funs.DB.HJGLData_HJGL
|
|
where x.ReportDate < DateTime.Now.AddDays(1).Date && x.ReportDate >= DateTime.Now.Date
|
|
select x).ToList();
|
|
if (q.Count > 0) result = true;
|
|
return result;
|
|
}
|
|
|
|
public static ReturnData PushCncec(string Id)
|
|
{
|
|
var baseurl = "/api/HJGLData/SaveHJGLData";
|
|
var item = GetItemById(Id);
|
|
var str = JsonConvert.SerializeObject(item);
|
|
var responeData = ServerService.PushCNCEC(str, baseurl);
|
|
return responeData;
|
|
}
|
|
|
|
public static HJGLData StatisticalData()
|
|
{
|
|
var data = new HJGLData();
|
|
var thisUnitId = string.Empty;
|
|
var thisUnit = CommonService.GetIsThisUnit();
|
|
if (thisUnit != null) thisUnitId = thisUnit.UnitId;
|
|
var baseUnit = UnitService.GetUnitByUnitId(thisUnitId);
|
|
var ProjectData = (from x in Funs.DB.Project_HJGLData_HJGL
|
|
where x.ReportDate < DateTime.Now.AddDays(1).Date && x.ReportDate >= DateTime.Now.Date
|
|
select x).ToList();
|
|
Project_HJGLData_HJGLService.StatisticalAllProjectData();
|
|
Project_HJGLData_DefectService.StatisticalAllProjectData();
|
|
|
|
var table = new HJGLData_HJGL
|
|
{
|
|
UnitId = thisUnitId,
|
|
CollCropCode = baseUnit.CollCropCode,
|
|
UnitName = baseUnit.UnitName,
|
|
ReportDate = DateTime.Now.Date,
|
|
WelderNum = ProjectData.Sum(x => x.WelderNum),
|
|
TotalDineNum = ProjectData.Sum(x => x.TotalDineNum),
|
|
CompleteDineNum = ProjectData.Sum(x => x.CompleteDineNum),
|
|
TotalFilmNum = ProjectData.Sum(x => x.TotalFilmNum),
|
|
OKFilmNum = ProjectData.Sum(x => x.OKFilmNum),
|
|
CreateMan = Const.sysglyId,
|
|
CreateDate = DateTime.Now
|
|
};
|
|
if (IsReportByToday())
|
|
{
|
|
table.Id = GetTodayData().Id;
|
|
table.State = Const.CNCEC_State_1;
|
|
UpdateHJGLData_HJGL(table);
|
|
}
|
|
else
|
|
{
|
|
table.Id = SQLHelper.GetNewID();
|
|
table.State = Const.CNCEC_State_0;
|
|
|
|
AddHJGLData_HJGL(table);
|
|
}
|
|
|
|
var item = new HJGLDataItem();
|
|
item.CollCropCode = table.CollCropCode;
|
|
item.CompleteDineNum = table.CompleteDineNum;
|
|
item.Id = table.Id;
|
|
item.OKFilmNum = table.OKFilmNum;
|
|
item.ReportDate = table.ReportDate.Value.ToShortDateString();
|
|
item.TotalDineNum = table.TotalDineNum;
|
|
item.TotalFilmNum = table.TotalFilmNum;
|
|
item.UnitId = table.UnitId;
|
|
item.WelderNum = table.WelderNum;
|
|
item.HJGLDataDefectItems = Project_HJGLData_DefectService.getTodayProject_HJGLData_Defect();
|
|
var hJGLDataItems = new List<HJGLDataItem>();
|
|
hJGLDataItems.Add(item);
|
|
|
|
data.HJGLDataItems = hJGLDataItems;
|
|
return data;
|
|
}
|
|
|
|
public static void UpdateHJGLData_HJGL(HJGLData_HJGL newtable)
|
|
{
|
|
using (Model.SGGLDB db = new Model.SGGLDB(Funs.ConnString))
|
|
{
|
|
var table = db.HJGLData_HJGL.FirstOrDefault(x => x.Id == newtable.Id);
|
|
if (table != null)
|
|
{
|
|
table.Id = newtable.Id;
|
|
table.UnitId = newtable.UnitId;
|
|
table.CollCropCode = newtable.CollCropCode;
|
|
table.UnitName = newtable.UnitName;
|
|
table.ReportDate = newtable.ReportDate;
|
|
table.WelderNum = newtable.WelderNum;
|
|
table.TotalDineNum = newtable.TotalDineNum;
|
|
table.CompleteDineNum = newtable.CompleteDineNum;
|
|
table.TotalFilmNum = newtable.TotalFilmNum;
|
|
table.OKFilmNum = newtable.OKFilmNum;
|
|
table.State = newtable.State;
|
|
table.CreateMan = newtable.CreateMan;
|
|
table.CreateDate = newtable.CreateDate;
|
|
db.SubmitChanges();
|
|
}
|
|
}
|
|
|
|
}
|
|
}
|
|
} |