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

312 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
{
8 months ago
/// <summary>
/// 泡沫、注塑点检
/// </summary>
5 months ago
[RoutePrefix("api/MachineClass")]
public class MachineClassController : ApiController
{
8 months ago
/// <summary>
/// 获取点检项
/// </summary>
/// <param name="MachineCode"></param>
/// <returns></returns>
5 months ago
[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;
}
8 months ago
/// <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")
{
7 months ago
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
{
7 months ago
if (resObj.dataList[i].SelectValue == "4")
t.MValue = "停机状态";
else
t.MValue = resObj.dataList[i].SelectValue;
}
}
SqlData.InsertMachine(t);
}
8 months ago
var Response = new Response();
return Ok(Response);
}
/// <summary>
/// 获取注塑点检项
/// </summary>
/// <param name="MachineCode"></param>
5 months ago
/// <param name="ProductCode"></param>
8 months ago
/// <returns></returns>
[HttpGet]
5 months ago
[Route("GZhuSuItem")]
public Response<List<MachineClass>> GZhuSuItem( string Machine, string ProductCode)
8 months ago
{
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);
5 months ago
8 months ago
var sqlValue = $"select * from T_MD_PutMachine where MachineCode ='{Machine}' ";
DataSet dataSetValue = SqlHelper.ExecuteDataset(Config.maindbConnectionString, CommandType.Text, sqlValue);
5 months ago
var sql_selectProduct = $"select * from monitordata where QrCodeContent = '{ProductCode}'";
//HoldEndPos
DataSet sql_selectSetValue = SqlHelper.ExecuteDataset(Config.maindbConnectionString, CommandType.Text, sql_selectProduct);
8 months ago
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)
{
4 months ago
if (sql_selectSetValue.Tables[0].Rows.Count > 0)
8 months ago
{
4 months ago
foreach (DataRow R in dataSet.Tables[0].Rows)
5 months ago
{
4 months ago
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);
5 months ago
}
8 months ago
4 months ago
result.Result = list_MachineClass;
}
else
{
result.Code = 202;
result.Message = "产品信息不存在";
8 months ago
}
}
else
{
4 months ago
8 months ago
}
return result;
}
}
}