天津投入产出系统后端
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.
 
 
 
 
 
 

284 lines
11 KiB

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using QMAPP.FJC.Entity.ProcessParameter;
using QMAPP.FJC.Entity.Operation;
using System.Data;
using QMFrameWork.Data;
using QMFrameWork.Common.Util;
namespace EQUIPINTERFACETEST.Deal
{
public class MillDeal
{
public void InsertParameter()
{
string sample = "select * from T_AW_MILINGPARAMETERSAMPLE ";
List<MilingParameter> sampleList = new List<MilingParameter>();
string dateStr = @"select datestr from(
select cast(m.OPERATEDDATE as date) as datestr,1 as piece from T_AW_MAINOPERATION m where processtype='12' and OPERATESTATE='2')t
group by datestr having sum(1)>5";
List<MainOperation> list = new List<MainOperation>();
string moSql = "select * from T_AW_MAINOPERATION m where processtype='12' 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<MilingParameter>(sample, new List<DataParameter>().ToArray()).ToList<MilingParameter>();
}
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<MilingParameter> insertListParameter = new List<MilingParameter>();
foreach (var mo in molist)
{
mo.OPERATESTATE = "1";
mo.PRODUCTCODESTR += ".";
MilingParameter bpindex = sampleList[0];
MilingParameter bp = new MilingParameter();
bp = BindHelper.CopyToModel<MilingParameter, MilingParameter>(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<MilingParameter>(bp);
Console.WriteLine(bp.PRODUCTCODE + " - " + i.ToString());
WriteLog.Write(bp.PRODUCTCODE + " - " + i.ToString());
}
}
}
public void InsertPressParameter()
{
string sample = "select * from T_AW_MILINGPARAMETERSAMPLE ";
List<MilingParameter> sampleList = new List<MilingParameter>();
MainOperation moSample = new MainOperation();
moSample.PID = "36a10c8c-4aa6-4fd6-bd05-8f6e09264d8b";
string mainSql = @"SELECT * FROM T_aw_main m where m.CURRENTPROCESS>'12' and m.CREATEDATE>'2016-05-1 00:24:32.427'
and not exists(select 1 from T_AW_MAINOPERATION mo where mo.processtype='12' and mo.PDID=m.PID)";
List<Main> mainList = new List<Main>();
string sqlMao = @"select * from T_AW_MAINOPERATION mo where mo.PROCESSTYPE='13' and exists(
select 1 from (
SELECT m.pid FROM T_aw_main m where m.CURRENTPROCESS>'12'
and not exists(select 1 from T_AW_MAINOPERATION mo where mo.processtype='12' and mo.PDID=m.PID))f
where f.PID=mo.PDID)";
List<MainOperation> maoList = new List<MainOperation>();
using (IDataSession session = AppDataFactory.CreateMainSession())
{
mainList = session.GetList<Main>(mainSql, new List<DataParameter>().ToArray()).ToList<Main>();
sampleList = session.GetList<MilingParameter>(sample, new List<DataParameter>().ToArray()).ToList<MilingParameter>();
moSample = session.Get<MainOperation>(moSample);
maoList = session.GetList<MainOperation>(sqlMao, new List<DataParameter>().ToArray()).ToList<MainOperation>();
}
List<MilingParameter> insertListParameter = new List<MilingParameter>();
List<MainOperation> molist = new List<MainOperation>();
foreach (Main m in mainList)
{
if(maoList.Count(o=>o.PRODUCTCODE==m.EPIDERMISCODE)==0)
{
continue;
}
MainOperation maoJie = maoList.First(o => o.PRODUCTCODE == m.EPIDERMISCODE);
MilingParameter bpindex = new MilingParameter();
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 = maoJie.OPERATEDDATE.AddSeconds(-20);
mo.CREATEDATE = mo.OPERATEDDATE.AddSeconds(-55);
mo.UPDATEDATE = mo.OPERATEDDATE;
mo.PRODUCTCODESTR = ".";
molist.Add(mo);
bpindex = sampleList[0];
MilingParameter bp = new MilingParameter();
bp = BindHelper.CopyToModel<MilingParameter, MilingParameter>(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<MilingParameter>(bp);
Console.WriteLine(bp.PRODUCTCODE + " - " + i.ToString());
WriteLog.Write(bp.PRODUCTCODE + " - " + i.ToString());
}
}
}
public void InsertMillParameter()
{
string sample = "select * from T_AW_MILINGPARAMETERSAMPLE ";
List<MilingParameter> sampleList = new List<MilingParameter>();
MainOperation moSample = new MainOperation();
moSample.PID = "36a10c8c-4aa6-4fd6-bd05-8f6e09264d8b";
string mainSql = @"SELECT * FROM T_aw_main m where m.CURRENTPROCESS='12' and m.CREATEDATE>'2016-05-13 14:06:28' and m.CREATEDATE<'2017-01-1 00:00:00'";
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<MilingParameter>(sample, new List<DataParameter>().ToArray()).ToList<MilingParameter>();
moSample = session.Get<MainOperation>(moSample);
}
List<MilingParameter> insertListParameter = new List<MilingParameter>();
List<MainOperation> molist = new List<MainOperation>();
foreach (Main m in mainList)
{
m.UPDATEDATE = m.UPDATEDATE.AddSeconds(90);
m.CURRENTPROCESS = "13";
MilingParameter bpindex = new MilingParameter();
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);
bpindex=sampleList[0];
MilingParameter bp = new MilingParameter();
bp = BindHelper.CopyToModel<MilingParameter, MilingParameter>(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<MilingParameter>(bp);
Console.WriteLine(bp.PRODUCTCODE + " - " + i.ToString());
WriteLog.Write(bp.PRODUCTCODE + " - " + i.ToString());
}
}
}
}
}