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.
311 lines
12 KiB
311 lines
12 KiB
using System;
|
|
using System.Collections.Generic;
|
|
using System.Data;
|
|
using System.Linq;
|
|
using System.Threading.Tasks;
|
|
using System.Web.Http;
|
|
using WebAPI.App_Start;
|
|
using WebAPI.Models;
|
|
using Newtonsoft.Json.Converters;
|
|
|
|
namespace WebAPI.Controllers
|
|
{
|
|
/// <summary>
|
|
/// 泡沫、注塑点检
|
|
/// </summary>
|
|
[RoutePrefix("api/MachineClass")]
|
|
public class MachineClassController : ApiController
|
|
{
|
|
/// <summary>
|
|
/// 获取点检项
|
|
/// </summary>
|
|
/// <param name="MachineCode"></param>
|
|
/// <returns></returns>
|
|
[HttpGet]
|
|
public Response<List<MachineClass>> Get(string MachineCode)
|
|
{
|
|
var result = new Response<List<MachineClass>>();
|
|
|
|
var sqlScript = $"select a.*,(select top 1 MValue from T_MD_PutMachineValue where MachineCode = a.PID ORDER BY CreateData ) as 'MValue',(select top 1 PValue from T_MD_PutMachineValue where MachineCode = a.PID ORDER BY CreateData ) as 'PValue' from T_MD_PutMachineClass as a where a.MachineCode = '{MachineCode}' ORDER BY a.SerialNumber ";
|
|
DataSet dataSet = SqlHelper.ExecuteDataset(Config.maindbConnectionString, CommandType.Text, sqlScript);
|
|
|
|
var sqlValue = $"select * from T_MD_PutMachine where MachineCode ='{MachineCode}' ";
|
|
DataSet dataSetValue = SqlHelper.ExecuteDataset(Config.maindbConnectionString, CommandType.Text, sqlValue);
|
|
|
|
|
|
|
|
var list_PutMachine = new List<PutMachine>();
|
|
foreach (DataRow R in dataSetValue.Tables[0].Rows)
|
|
{
|
|
var t = new PutMachine();
|
|
t.PID = R["PID"].ToString();
|
|
t.MachineCode = R["MachineCode"].ToString();
|
|
t.MachinePID = R["MachinePID"].ToString();
|
|
t.Limit = R["Limit"].ToString();
|
|
t.Floor = R["Floor"].ToString();
|
|
t.Name = R["Name"].ToString();
|
|
t.SerialNumber = Convert.ToInt32(R["SerialNumber"].ToString());
|
|
list_PutMachine.Add(t);
|
|
}
|
|
|
|
var list_MachineClass = new List<MachineClass>();
|
|
if (dataSet.Tables[0].Rows.Count > 0)
|
|
{
|
|
foreach (DataRow R in dataSet.Tables[0].Rows)
|
|
{
|
|
var t = new MachineClass();
|
|
t.PID = R["PID"].ToString();
|
|
t.MachineCode = R["MachineCode"].ToString();
|
|
t.Name = R["Name"].ToString();
|
|
t.Position = R["Position"].ToString();
|
|
t.Content = R["Content"].ToString();
|
|
t.Methond = R["Methond"].ToString();
|
|
t.Type = R["Type"].ToString();
|
|
t.SerialNumber = R["SerialNumber"].ToString();
|
|
|
|
var m = list_PutMachine.Where(p => p.MachinePID == t.PID).OrderBy(o=>o.SerialNumber).ToList();
|
|
t.putMachine = m;
|
|
|
|
switch (t.Type)
|
|
{
|
|
case "1":
|
|
t.SelectName = R["MValue"].ToString();
|
|
if (!string.IsNullOrEmpty(t.SelectName))
|
|
{
|
|
switch (t.SelectName)
|
|
{
|
|
case "状态良好":
|
|
t.SelectValue = "1";
|
|
break;
|
|
case "正在处理":
|
|
t.SelectValue = "2";
|
|
break;
|
|
case "状态不好或损毁":
|
|
t.SelectValue = "3";
|
|
break;
|
|
case "停机状态":
|
|
t.SelectValue = "4";
|
|
break;
|
|
}
|
|
}
|
|
else
|
|
{
|
|
t.SelectName = "";
|
|
t.SelectValue = "";
|
|
}
|
|
break;
|
|
case "2":
|
|
t.SelectName = R["MValue"].ToString();
|
|
t.SelectValue = R["MValue"].ToString();
|
|
break;
|
|
case "3":
|
|
t.putMachine[0].SelectName = R["MValue"].ToString();
|
|
t.putMachine[1].SelectName = R["PValue"].ToString();
|
|
break;
|
|
}
|
|
|
|
list_MachineClass.Add(t);
|
|
}
|
|
|
|
result.Result = list_MachineClass;
|
|
}
|
|
else
|
|
{
|
|
result.Code = 201;
|
|
result.Message = "设备信息不存在";
|
|
}
|
|
|
|
return result;
|
|
}
|
|
|
|
/// <summary>
|
|
/// 点检录入
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
public async Task<IHttpActionResult> Insert()
|
|
{
|
|
var request = await this.Request.Content.ReadAsStringAsync();
|
|
|
|
var requeststr = request.Replace("\r", "").Replace("\n", "");
|
|
|
|
var resObj = JsonHelper.Instance.JsonToObj<ReceiveMachine>(requeststr);
|
|
|
|
var group = "";//班次
|
|
switch (resObj.groupValue)
|
|
{
|
|
case "1":
|
|
group = "三班";
|
|
break;
|
|
case "2":
|
|
group = "白班";
|
|
break;
|
|
case "3":
|
|
group = "二班";
|
|
break;
|
|
}
|
|
var item = resObj.dataList[resObj.dataList.Count - 1];
|
|
|
|
|
|
for (var i = 0; i < resObj.dataList.Count-1; i++)
|
|
{
|
|
var t = new MachineValue();
|
|
t.UserName = resObj.id;
|
|
t.MachineCode = resObj.dataList[i].PID;
|
|
t.Name = resObj.dataList[i].Content;
|
|
t.Type = resObj.dataList[i].Type;
|
|
t.Group = group;
|
|
t.UserName = resObj.id;
|
|
|
|
if (resObj.dataList[i].Type == "3")
|
|
{
|
|
if (resObj.dataList[i].SelectValue == "4")
|
|
{
|
|
t.MValue = "停机状态";
|
|
t.PValue = "停机状态";
|
|
}
|
|
else
|
|
{
|
|
t.MValue = resObj.dataList[i].putMachine[0].SelectName;
|
|
t.PValue = resObj.dataList[i].putMachine[1].SelectName;
|
|
}
|
|
}
|
|
else
|
|
{
|
|
if (resObj.dataList[i].Type == "1")
|
|
{
|
|
switch (resObj.dataList[i].SelectValue)
|
|
{
|
|
case "1":
|
|
t.MValue = "状态良好";
|
|
break;
|
|
case "2":
|
|
t.MValue = "正在处理";
|
|
break;
|
|
case "3":
|
|
t.MValue = "状态不好或损毁";
|
|
break;
|
|
case "4":
|
|
t.MValue = "停机状态";
|
|
break;
|
|
}
|
|
}
|
|
else
|
|
{
|
|
if (resObj.dataList[i].SelectValue == "4")
|
|
t.MValue = "停机状态";
|
|
else
|
|
t.MValue = resObj.dataList[i].SelectValue;
|
|
}
|
|
}
|
|
|
|
SqlData.InsertMachine(t);
|
|
}
|
|
|
|
var Response = new Response();
|
|
|
|
return Ok(Response);
|
|
}
|
|
|
|
/// <summary>
|
|
/// 获取注塑点检项
|
|
/// </summary>
|
|
/// <param name="MachineCode"></param>
|
|
/// <param name="ProductCode"></param>
|
|
/// <returns></returns>
|
|
[HttpGet]
|
|
[Route("GZhuSuItem")]
|
|
public Response<List<MachineClass>> GZhuSuItem( string Machine, string ProductCode)
|
|
{
|
|
var result = new Response<List<MachineClass>>();
|
|
|
|
var sqlScript = $"select a.* from T_MD_PutMachineClass as a where a.MachineCode = '{Machine}' ORDER BY a.SerialNumber ";
|
|
DataSet dataSet = SqlHelper.ExecuteDataset(Config.maindbConnectionString, CommandType.Text, sqlScript);
|
|
|
|
var sqlValue = $"select * from T_MD_PutMachine where MachineCode ='{Machine}' ";
|
|
DataSet dataSetValue = SqlHelper.ExecuteDataset(Config.maindbConnectionString, CommandType.Text, sqlValue);
|
|
|
|
var sql_selectProduct = $"select * from monitordata where QrCodeContent = '{ProductCode}'";
|
|
//HoldEndPos
|
|
DataSet sql_selectSetValue = SqlHelper.ExecuteDataset(Config.maindbConnectionString, CommandType.Text, sql_selectProduct);
|
|
|
|
var list_PutMachine = new List<PutMachine>();
|
|
foreach (DataRow R in dataSetValue.Tables[0].Rows)
|
|
{
|
|
var t = new PutMachine();
|
|
t.PID = R["PID"].ToString();
|
|
t.MachineCode = R["MachineCode"].ToString();
|
|
t.MachinePID = R["MachinePID"].ToString();
|
|
t.Limit = R["Limit"].ToString();
|
|
t.Floor = R["Floor"].ToString();
|
|
t.Name = R["Name"].ToString();
|
|
t.SerialNumber = Convert.ToInt32(R["SerialNumber"].ToString());
|
|
list_PutMachine.Add(t);
|
|
}
|
|
|
|
var list_MachineClass = new List<MachineClass>();
|
|
if (dataSet.Tables[0].Rows.Count > 0)
|
|
{
|
|
if (sql_selectSetValue.Tables[0].Rows.Count > 0)
|
|
{
|
|
foreach (DataRow R in dataSet.Tables[0].Rows)
|
|
{
|
|
var t = new MachineClass();
|
|
t.PID = R["PID"].ToString();
|
|
t.MachineCode = R["MachineCode"].ToString();
|
|
t.Name = R["Name"].ToString();
|
|
t.Position = R["Position"].ToString();
|
|
t.Content = R["Content"].ToString();
|
|
t.Methond = R["Methond"].ToString();
|
|
t.Type = R["Type"].ToString();
|
|
t.SerialNumber = R["SerialNumber"].ToString();
|
|
|
|
var m = list_PutMachine.Where(p => p.MachinePID == t.PID).OrderBy(o => o.SerialNumber).ToList();
|
|
t.putMachine = m;
|
|
|
|
if (sql_selectSetValue.Tables[0].Rows.Count > 0)
|
|
{
|
|
if (R["SerialNumber"].ToString() == "1")
|
|
{
|
|
//注塑开始位置
|
|
t.SelectName = sql_selectSetValue.Tables[0].Rows[0]["InjectStartPos"].ToString();
|
|
t.SelectValue = sql_selectSetValue.Tables[0].Rows[0]["InjectStartPos"].ToString();
|
|
}
|
|
else if (R["SerialNumber"].ToString() == "2")
|
|
{
|
|
//保压结束位置
|
|
t.SelectName = sql_selectSetValue.Tables[0].Rows[0]["HoldEndPos"].ToString();
|
|
t.SelectValue = sql_selectSetValue.Tables[0].Rows[0]["HoldEndPos"].ToString();
|
|
}
|
|
else if (R["SerialNumber"].ToString() == "3")
|
|
{
|
|
//储料完成位置
|
|
t.SelectName = sql_selectSetValue.Tables[0].Rows[0]["ChargeEndPos"].ToString();
|
|
t.SelectValue = sql_selectSetValue.Tables[0].Rows[0]["ChargeEndPos"].ToString();
|
|
}
|
|
}
|
|
else
|
|
{
|
|
t.SelectName = "0";
|
|
t.SelectValue = "0";
|
|
}
|
|
|
|
list_MachineClass.Add(t);
|
|
}
|
|
|
|
result.Result = list_MachineClass;
|
|
}
|
|
else
|
|
{
|
|
result.Code = 202;
|
|
result.Message = "产品信息不存在";
|
|
}
|
|
}
|
|
else
|
|
{
|
|
|
|
}
|
|
|
|
return result;
|
|
}
|
|
}
|
|
}
|
|
|