天津投入产出系统后端
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

281 lines
11 KiB

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using QMFrameWork.Data;
using System.Data;
using QMAPP.FJC.Entity.Operation;
using QMAPP.FJC.Entity.ProcessParameter;
using QMFrameWork.Common.Util;
namespace EQUIPINTERFACETEST.Deal
{
public class PunchDeal
{
public void InsertParameter()
{
string sample = "select * from T_AW_PUNCHPARAMETERsample ";
List<PunchParameter> sampleList = new List<PunchParameter>();
string dateStr = @"select datestr from(
select cast(m.OPERATEDDATE as date) as datestr,1 as piece from T_AW_MAINOPERATION m where processtype='11' and OPERATESTATE='2')t
group by datestr having sum(1)>10";
List<MainOperation> list = new List<MainOperation>();
string moSql = "select * from T_AW_MAINOPERATION m where processtype='11' and OPERATESTATE='2'";
DataTable dt=new DataTable();
using (IDataSession session = AppDataFactory.CreateMainSession())
{
dt = session.GetTable(dateStr, new List<DataParameter>().ToArray());
list = session.GetList<MainOperation>(moSql, new List<DataParameter>().ToArray()).ToList<MainOperation>();
sampleList = session.GetList<PunchParameter>(moSql, new List<DataParameter>().ToArray()).ToList<PunchParameter>();
}
List<MainOperation> molist = new List<MainOperation>();
for (int i = 0; i < dt.Rows.Count; i++)
{
string dayStr = dt.Rows[i][0].ToString();
DateTime dt1 = Convert.ToDateTime(dayStr);
List<MainOperation> list1 = list.Where(o => o.OPERATEDDATE > dt1 && o.OPERATEDDATE < dt1.AddDays(1)).ToList<MainOperation>();
molist = molist.Concat(list1).ToList<MainOperation>();
}
List<PunchParameter> insertListParameter = new List<PunchParameter>();
foreach (var mo in molist)
{
mo.OPERATESTATE = "1";
mo.PRODUCTCODESTR += ".";
PunchParameter bpindex = new PunchParameter();
if (mo.PRODUCTCODE.Substring(12, 1) == "H")
{
bpindex = sampleList.First(o => o.PRODUCTCODE.Substring(12, 1) == "H");
}
else
{
bpindex = sampleList.First(o => o.PRODUCTCODE.Substring(12, 1) == "B");
}
PunchParameter bp = new PunchParameter();
bp = BindHelper.CopyToModel<PunchParameter, PunchParameter>(bpindex, false);
bp.PID = Guid.NewGuid().ToString();
bp.PDID = mo.PDID;
bp.MOID = mo.PID;
bp.PRODUCTCODE = mo.PRODUCTCODE;
bp.CREATEDATE = mo.OPERATEDDATE;
insertListParameter.Add(bp);
}
using (IDataSession session = AppDataFactory.CreateMainSession())
{
int j = 0;
foreach (var mo in molist)
{
j++;
session.Update<MainOperation>(mo);
Console.WriteLine(mo.PRODUCTCODE + " - " + j.ToString());
WriteLog.Write(mo.PRODUCTCODE + " - " + j.ToString());
}
int i = 0;
foreach (var bp in insertListParameter)
{
i++;
session.Insert<PunchParameter>(bp);
Console.WriteLine(bp.PRODUCTCODE + " - " + i.ToString());
WriteLog.Write(bp.PRODUCTCODE + " - " + i.ToString());
}
}
}
public void InsertPressParameter()
{
string sample = "select * from T_AW_PUNCHPARAMETERsample ";
List<PunchParameter> sampleList = new List<PunchParameter>();
MainOperation moSample = new MainOperation();
moSample.PID = "60394a90-4adf-4331-8d2c-a6f69ab0c1f0";
string mainSql = @"SELECT * FROM T_aw_main m where m.CURRENTPROCESS>'11'
and not exists(select 1 from T_AW_MAINOPERATION mo where mo.processtype='11' and mo.PDID=m.PID)";
List<Main> mainList = new List<Main>();
using (IDataSession session = AppDataFactory.CreateMainSession())
{
mainList = session.GetList<Main>(mainSql, new List<DataParameter>().ToArray()).ToList<Main>();
sampleList = session.GetList<PunchParameter>(sample, new List<DataParameter>().ToArray()).ToList<PunchParameter>();
moSample = session.Get<MainOperation>(moSample);
}
List<PunchParameter> insertListParameter = new List<PunchParameter>();
List<MainOperation> molist = new List<MainOperation>();
foreach (Main m in mainList)
{
PunchParameter bpindex = new PunchParameter();
MainOperation mo = new MainOperation();
mo = BindHelper.CopyToModel<MainOperation, MainOperation>(moSample, false);
mo.PID = Guid.NewGuid().ToString();
mo.PDID = m.PID;
mo.PRODUCTCODE = m.EPIDERMISCODE;
mo.OPERATEDDATE = m.CREATEDATE.AddMinutes(90);
mo.CREATEDATE = mo.OPERATEDDATE.AddSeconds(-55);
mo.UPDATEDATE = mo.OPERATEDDATE;
mo.PRODUCTCODESTR = ".";
molist.Add(mo);
if (m.EPIDERMISCODE.Substring(12, 1) == "H")
{
bpindex = sampleList.First(o => o.PRODUCTCODE.Substring(12, 1) == "H");
}
else
{
bpindex = sampleList.First(o => o.PRODUCTCODE.Substring(12, 1) == "B");
}
PunchParameter bp = new PunchParameter();
bp = BindHelper.CopyToModel<PunchParameter, PunchParameter>(bpindex, false);
bp.PID = Guid.NewGuid().ToString();
bp.PDID = mo.PDID;
bp.MOID = mo.PID;
bp.PRODUCTCODE = mo.PRODUCTCODE;
bp.CREATEDATE = mo.OPERATEDDATE;
insertListParameter.Add(bp);
}
using (IDataSession session = AppDataFactory.CreateMainSession())
{
int j = 0;
foreach (var mo in molist)
{
j++;
session.Insert<MainOperation>(mo);
Console.WriteLine(mo.PRODUCTCODE + " - " + j.ToString());
WriteLog.Write(mo.PRODUCTCODE + " - " + j.ToString());
}
int i = 0;
foreach (var bp in insertListParameter)
{
i++;
session.Insert<PunchParameter>(bp);
Console.WriteLine(bp.PRODUCTCODE + " - " + i.ToString());
WriteLog.Write(bp.PRODUCTCODE + " - " + i.ToString());
}
}
}
public void InsertPunchParameter()
{
string sample = "select * from T_AW_PUNCHPARAMETERsample ";
List<PunchParameter> sampleList = new List<PunchParameter>();
MainOperation moSample = new MainOperation();
moSample.PID = "60394a90-4adf-4331-8d2c-a6f69ab0c1f0";
string mainSql = @"SELECT * FROM T_aw_main m where m.CURRENTPROCESS='11' and m.CREATEDATE>'2016-05-13 14:06:28' and m.CREATEDATE<'2017-01-1 00:00:00' AND SUBSTRING(m.EPIDERMISCODE,13,1)='B'";
List<Main> mainList = new List<Main>();
using (IDataSession session = AppDataFactory.CreateMainSession())
{
mainList = session.GetList<Main>(mainSql, new List<DataParameter>().ToArray()).ToList<Main>();
sampleList = session.GetList<PunchParameter>(sample, new List<DataParameter>().ToArray()).ToList<PunchParameter>();
moSample = session.Get<MainOperation>(moSample);
}
List<PunchParameter> insertListParameter = new List<PunchParameter>();
List<MainOperation> molist = new List<MainOperation>();
foreach (Main m in mainList)
{
m.UPDATEDATE = m.UPDATEDATE.AddHours(90);
m.CURRENTPROCESS = "12";
PunchParameter bpindex = new PunchParameter();
MainOperation mo = new MainOperation();
mo = BindHelper.CopyToModel<MainOperation, MainOperation>(moSample, false);
mo.PID = Guid.NewGuid().ToString();
mo.PDID = m.PID;
mo.PRODUCTCODE = m.EPIDERMISCODE;
mo.OPERATEDDATE = m.UPDATEDATE;
mo.CREATEDATE = mo.OPERATEDDATE.AddSeconds(-55);
mo.UPDATEDATE = mo.OPERATEDDATE;
mo.PRODUCTCODESTR = ".";
molist.Add(mo);
if (m.EPIDERMISCODE.Substring(12, 1) == "H")
{
bpindex = sampleList.First(o => o.PRODUCTCODE.Substring(12, 1) == "H");
}
else
{
bpindex = sampleList.First(o => o.PRODUCTCODE.Substring(12, 1) == "B");
}
PunchParameter bp = new PunchParameter();
bp = BindHelper.CopyToModel<PunchParameter, PunchParameter>(bpindex, false);
bp.PID = Guid.NewGuid().ToString();
bp.PDID = mo.PDID;
bp.MOID = mo.PID;
bp.PRODUCTCODE = mo.PRODUCTCODE;
bp.CREATEDATE = mo.OPERATEDDATE;
insertListParameter.Add(bp);
}
using (IDataSession session = AppDataFactory.CreateMainSession())
{
int c = 0;
foreach (var m in mainList)
{
c++;
session.Update<Main>(m);
Console.WriteLine(m.EPIDERMISCODE + " - " + c.ToString());
WriteLog.Write(m.EPIDERMISCODE + " - " + c.ToString());
}
int j = 0;
foreach (var mo in molist)
{
j++;
session.Insert<MainOperation>(mo);
Console.WriteLine(mo.PRODUCTCODE + " - " + j.ToString());
WriteLog.Write(mo.PRODUCTCODE + " - " + j.ToString());
}
int i = 0;
foreach (var bp in insertListParameter)
{
i++;
session.Insert<PunchParameter>(bp);
Console.WriteLine(bp.PRODUCTCODE + " - " + i.ToString());
WriteLog.Write(bp.PRODUCTCODE + " - " + i.ToString());
}
}
}
}
}