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.
290 lines
15 KiB
290 lines
15 KiB
using QMAPP.BLL.Sys;
|
|
using QMAPP.DAL.Sys;
|
|
using QMAPP.Entity.Sys;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Data;
|
|
using System.Linq;
|
|
using System.Net;
|
|
using System.Net.Http;
|
|
using System.Threading.Tasks;
|
|
using System.Web.Http;
|
|
using WebAPI.App_Start;
|
|
using WebAPI.Models;
|
|
|
|
namespace WebAPI.Controllers
|
|
{
|
|
|
|
public class InventoryController : ApiController
|
|
{
|
|
public Response<List<OrderPlan_PaoMo>> GetPlanList(string state,string Type)
|
|
{
|
|
//state = ok 合格品
|
|
//state = nok 不良品
|
|
var result = new Response<List<OrderPlan_PaoMo>>();
|
|
|
|
List<OrderPlan_PaoMo> List_plan = new List<OrderPlan_PaoMo>();
|
|
|
|
var sqlScript = "";
|
|
|
|
|
|
|
|
if (Type == "1")
|
|
{
|
|
if (state == "ok")
|
|
{
|
|
sqlScript = $"select p.*,m.MATERIAL_NAME from T_PP_ORDERPLAN_PAOMO p left join T_MD_MATERIAL m on m.MATERIAL_CODE = p.MATERIAL_CODE where p.PLAN_STATE = '0' order by p.PLAN_DATE desc,p.PLAN_NO";
|
|
}
|
|
else
|
|
{
|
|
sqlScript = $"select top 20 p.*,m.MATERIAL_NAME from T_PP_ORDERPLAN_PAOMO p left join T_MD_MATERIAL m on m.MATERIAL_CODE = p.MATERIAL_CODE order by p.PLAN_DATE desc,p.PLAN_NO";
|
|
|
|
}
|
|
}
|
|
else
|
|
{
|
|
if (state == "ok")
|
|
{
|
|
sqlScript = $"select p.*,m.MATERIAL_NAME from T_PP_ORDERPLAN_ZHUSU p left join T_MD_MATERIAL m on m.MATERIAL_CODE = p.MATERIAL_CODE where p.PLAN_STATE = '0' order by p.PLAN_DATE desc,p.PLAN_NO";
|
|
|
|
}
|
|
else
|
|
{
|
|
sqlScript = $"select top 20 p.*,m.MATERIAL_NAME from T_PP_ORDERPLAN_ZHUSU p left join T_MD_MATERIAL m on m.MATERIAL_CODE = p.MATERIAL_CODE order by p.PLAN_DATE desc,p.PLAN_NO";
|
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
DataSet dataSet = SqlHelper.ExecuteDataset(Config.maindbConnectionString, CommandType.Text, sqlScript);
|
|
|
|
if (dataSet.Tables[0].Rows.Count > 0)
|
|
{
|
|
foreach (DataRow row in dataSet.Tables[0].Rows)
|
|
{
|
|
OrderPlan_PaoMo OrderPlan = new OrderPlan_PaoMo();
|
|
OrderPlan.PID = row["PID"].ToString();
|
|
OrderPlan.PLAN_NO = row["PLAN_NO"].ToString()+"\n"+ row["MATERIAL_NAME"].ToString();
|
|
OrderPlan.PLAN_SEQ = row["PLAN_SEQ"].ToString();
|
|
OrderPlan.PLAN_STATE = row["PLAN_STATE"].ToString();
|
|
OrderPlan.MATERIAL_CODE = row["MATERIAL_CODE"].ToString();
|
|
OrderPlan.PBOM_CODE = row["PBOM_CODE"].ToString();
|
|
OrderPlan.ROUTE_CODE = row["ROUTE_CODE"].ToString();
|
|
OrderPlan.QTY = row["QTY"].ToString();
|
|
OrderPlan.COMPLETE_QTY = row["COMPLETE_QTY"].ToString();
|
|
OrderPlan.PLAN_DATE = row["PLAN_DATE"].ToString();
|
|
OrderPlan.SHIFT_CODE = row["SHIFT_CODE"].ToString();
|
|
|
|
List_plan.Add(OrderPlan);
|
|
}
|
|
|
|
result.Result = List_plan;
|
|
}
|
|
else
|
|
{
|
|
result.Code = 201;
|
|
result.Message = "没有生产计划了";
|
|
}
|
|
|
|
return result;
|
|
}
|
|
[HttpGet]
|
|
public Response<List<DefectDict>> GetDefectDictList()
|
|
{
|
|
//state = ok
|
|
//state = nok
|
|
var result = new Response<List<DefectDict>>();
|
|
|
|
List<DefectDict> List_plan = new List<DefectDict>();
|
|
|
|
var sqlScript = "";
|
|
|
|
sqlScript = $"select * from T_AW_MENDRECORDERERP where TYPE_CODE = 'BC316_ASSLINE' order by MFGCODE ";
|
|
|
|
DataSet dataSet = SqlHelper.ExecuteDataset(Config.maindbConnectionString, CommandType.Text, sqlScript);
|
|
|
|
if (dataSet.Tables[0].Rows.Count > 0)
|
|
{
|
|
foreach (DataRow row in dataSet.Tables[0].Rows)
|
|
{
|
|
DefectDict OrderPlan = new DefectDict();
|
|
OrderPlan.PID = row["PID"].ToString();
|
|
OrderPlan.MFGCODETYPE = row["MFGCODETYPE"].ToString();
|
|
OrderPlan.MFGCODETYPENAME = row["MFGCODETYPENAME"].ToString();
|
|
OrderPlan.TYPE_CODE = row["TYPE_CODE"].ToString();
|
|
OrderPlan.MFGCODE = row["MFGCODE"].ToString();
|
|
OrderPlan.MFGNAME = row["MFGNAME"].ToString();
|
|
|
|
List_plan.Add(OrderPlan);
|
|
}
|
|
|
|
result.Result = List_plan;
|
|
}
|
|
else
|
|
{
|
|
result.Code = 201;
|
|
result.Message = "用户信息不存在";
|
|
}
|
|
|
|
return result;
|
|
}
|
|
|
|
public async Task<IHttpActionResult> Insert()
|
|
{
|
|
var request = await this.Request.Content.ReadAsStringAsync();
|
|
|
|
var requeststr = request.Replace("\r", "").Replace("\n", "");
|
|
|
|
var resObj = JsonHelper.Instance.JsonToObj<Inventory>(requeststr);
|
|
|
|
if (resObj.State == "2")
|
|
{
|
|
var sql = $"select * from T_PA_InOutPut_InventoryLog where ProductCode = '{resObj.ProductCode}' and State = '1'";
|
|
DataSet dataSet = SqlHelper.ExecuteDataset(Config.maindbConnectionString, CommandType.Text, sql);
|
|
if (dataSet.Tables[0].Rows.Count > 0)
|
|
{
|
|
var sql2 = $"update T_PA_InOutPut_Inventory set State = '2' ,UpdateUser='{resObj.User}',UpdateDate='{DateTime.Now}'where PID = (SELECT TOP 1 PID FROM T_PA_InOutPut_Inventory WHERE ProductCode = '{resObj.ProductCode}' ORDER BY UpdateDate DESC) ";
|
|
SqlData.InsertWare(sql2);
|
|
|
|
var sql_log = $"INSERT INTO [dbo].[T_PA_InOutPut_InventoryLog] ([PID], [ProductCode], [Type], [State], [CreateUser], [CreateDate]) VALUES " +
|
|
$"(NEWID(), '{resObj.ProductCode}', '{resObj.Type}', '2', '{resObj.User}', '{DateTime.Now}');";
|
|
SqlData.InsertWare(sql_log);
|
|
}
|
|
else
|
|
{
|
|
var ResponseNOK = new Response();
|
|
ResponseNOK.Code = 400;
|
|
ResponseNOK.Message = "当前条码未进行上悬链操作,禁止下悬链!";
|
|
return Ok(ResponseNOK);
|
|
}
|
|
}
|
|
else if (resObj.State == "1")
|
|
{
|
|
var sql = $"select * from T_PA_InOutPut_InventoryLog where ProductCode = '{resObj.ProductCode}' and State = '1'";
|
|
DataSet dataSet = SqlHelper.ExecuteDataset(Config.maindbConnectionString, CommandType.Text, sql);
|
|
if (dataSet.Tables[0].Rows.Count <= 0)
|
|
{
|
|
var sql2 = $"INSERT INTO [dbo].[T_PA_InOutPut_Inventory] ([PID], [ProductCode], [Type], [State], [CreateUser], [CreateDate], [UpdateUser], [UpdateDate], [Remark1], [Remark2], [Remark3], [PlanID], [MFGNAME]) VALUES " +
|
|
$"(NEWID(), '{resObj.ProductCode}', '{resObj.Type}', '1', '{resObj.User}', '{DateTime.Now}', '{resObj.User}', '{DateTime.Now}', NULL, NULL, NULL, '{resObj.PlanID.Substring(0,14)}', NULL);";
|
|
SqlData.InsertWare(sql2);
|
|
|
|
//泡沫修改完成数
|
|
if (resObj.Type == "1")
|
|
{
|
|
var sel3 = $"update [dbo].[T_PP_ORDERPLAN_PAOMO] set COMPLETE_QTY = COMPLETE_QTY + 1 where PLAN_NO = '{resObj.PlanID.Substring(0, 14)}'";
|
|
SqlData.InsertWare(sel3);
|
|
|
|
var select_pm = $"select * from T_PP_ORDERPLAN_PAOMO where PLAN_NO = '{resObj.PlanID.Substring(0, 14)}' and QTY <= COMPLETE_QTY";
|
|
DataSet select_pmdataSet = SqlHelper.ExecuteDataset(Config.maindbConnectionString, CommandType.Text, select_pm);
|
|
if (select_pmdataSet.Tables[0].Rows.Count > 0)
|
|
{
|
|
var QTY = select_pmdataSet.Tables[0].Rows[0]["QTY"].ToString();
|
|
var COMPLETE_QTY = select_pmdataSet.Tables[0].Rows[0]["COMPLETE_QTY"].ToString();
|
|
if (Convert.ToInt32(QTY) <= Convert.ToInt32(COMPLETE_QTY))
|
|
{
|
|
var sqlupdate = $"update [dbo].[T_PP_ORDERPLAN_PAOMO] set PLAN_STATE = '3' where PLAN_NO = '{resObj.PlanID.Substring(0, 14)}' and QTY <= COMPLETE_QTY ";
|
|
SqlData.InsertWare(sqlupdate);
|
|
}
|
|
}
|
|
}
|
|
else
|
|
{
|
|
var sel3 = $"update [dbo].[T_PP_ORDERPLAN_ZHUSU] set COMPLETE_QTY = COMPLETE_QTY + 1 where PLAN_NO = '{resObj.PlanID.Substring(0, 14)}'";
|
|
SqlData.InsertWare(sel3);
|
|
|
|
var select_pm = $"select * from T_PP_ORDERPLAN_ZHUSU where PLAN_NO = '{resObj.PlanID.Substring(0, 14)}' and QTY <= COMPLETE_QTY";
|
|
DataSet select_pmdataSet = SqlHelper.ExecuteDataset(Config.maindbConnectionString, CommandType.Text, select_pm);
|
|
if (select_pmdataSet.Tables[0].Rows.Count > 0)
|
|
{
|
|
var QTY = select_pmdataSet.Tables[0].Rows[0]["QTY"].ToString();
|
|
var COMPLETE_QTY = select_pmdataSet.Tables[0].Rows[0]["COMPLETE_QTY"].ToString();
|
|
if (Convert.ToInt32(QTY) <= Convert.ToInt32(COMPLETE_QTY))
|
|
{
|
|
var sqlupdate = $"update [dbo].[T_PP_ORDERPLAN_ZHUSU] set PLAN_STATE = '3' where PLAN_NO = '{resObj.PlanID.Substring(0, 14)}' and QTY <= COMPLETE_QTY ";
|
|
SqlData.InsertWare(sqlupdate);
|
|
}
|
|
}
|
|
|
|
#region 绑定投料最新批次
|
|
//查询最新批次
|
|
var select_sql = $"select a.*,(select top 1 planNumber from T_MD_RawMaterial where PartCode = a.RawMaterial ORDER BY CREATEDATE desc) as 'planNumber' from T_MD_RawMaterial_change a where a.MaterialCode = '{resObj.ProductCode.Substring(0,13)}';";
|
|
DataSet select_RawdataSet = SqlHelper.ExecuteDataset(Config.maindbConnectionString, CommandType.Text, select_sql);
|
|
|
|
if (select_RawdataSet.Tables[0].Rows.Count > 0)
|
|
{
|
|
//绑定投料记录
|
|
var insert_sql = $"INSERT INTO [dbo].[T_MD_RawMaterialRecord] ([PID], [RawMaterialPID], [ProductCode], [MaterialCode], [IsCheck], [CREATEUSER], [CREATEDATE], [UPDATEUSER], [UPDATEDATE], [MaterialName]) VALUES " +
|
|
$"(NEWID(), '{select_RawdataSet.Tables[0].Rows[0]["planNumber"].ToString()}', '{resObj.ProductCode}', '{select_RawdataSet.Tables[0].Rows[0]["RawMaterial"].ToString()}', '0', '{resObj.User}',GETDATE(), '{resObj.User}', GETDATE(), '{select_RawdataSet.Tables[0].Rows[0]["MaterialName"].ToString()}');";
|
|
SqlData.InsertWare(insert_sql);
|
|
|
|
}
|
|
|
|
#endregion
|
|
}
|
|
|
|
var sql_log = $"INSERT INTO [dbo].[T_PA_InOutPut_InventoryLog] ([PID], [ProductCode], [Type], [State], [CreateUser], [CreateDate]) VALUES " +
|
|
$"(NEWID(), '{resObj.ProductCode}', '{resObj.Type}', '1', '{resObj.User}', '{DateTime.Now}');";
|
|
SqlData.InsertWare(sql_log);
|
|
}
|
|
else
|
|
{
|
|
var ResponseNOK = new Response();
|
|
ResponseNOK.Code = 400;
|
|
ResponseNOK.Message = "零件已录入,禁止重复操作!";
|
|
return Ok(ResponseNOK);
|
|
}
|
|
}
|
|
else if (resObj.State == "3" || resObj.State == "4")
|
|
{
|
|
var sql = $"select * from T_PA_InOutPut_InventoryLog where ProductCode = '{resObj.ProductCode}' and State in ('3','4')";
|
|
DataSet dataSet = SqlHelper.ExecuteDataset(Config.maindbConnectionString, CommandType.Text, sql);
|
|
if (dataSet.Tables[0].Rows.Count <= 0)
|
|
{
|
|
var sql2 = $"INSERT INTO [dbo].[T_PA_InOutPut_Inventory] ([PID], [ProductCode], [Type], [State], [CreateUser], [CreateDate], [UpdateUser], [UpdateDate], [Remark1], [Remark2], [Remark3], [PlanID], [MFGNAME]) VALUES " +
|
|
$"(NEWID(), '{resObj.ProductCode}', '{resObj.Type}', '{resObj.State}', '{resObj.User}', '{DateTime.Now}', '{resObj.User}', '{DateTime.Now}', NULL, NULL, NULL, '{resObj.PlanID.Substring(0, 14)}', '{resObj.MFGNAME}');";
|
|
SqlData.InsertWare(sql2);
|
|
|
|
var sql_log = $"INSERT INTO [dbo].[T_PA_InOutPut_InventoryLog] ([PID], [ProductCode], [Type], [State], [CreateUser], [CreateDate]) VALUES " +
|
|
$"(NEWID(), '{resObj.ProductCode}', '{resObj.Type}', '{resObj.State}', '{resObj.User}', '{DateTime.Now}');";
|
|
SqlData.InsertWare(sql_log);
|
|
|
|
if (resObj.Type == "1" && resObj.State == "3")
|
|
{
|
|
var sel3 = $"update [dbo].[T_PP_ORDERPLAN_PAOMO] set REPAIR_QTY = REPAIR_QTY + 1 where PLAN_NO = '{resObj.PlanID.Substring(0, 14)}'";
|
|
SqlData.InsertWare(sel3);
|
|
}
|
|
else if (resObj.Type == "1" && resObj.State == "4")
|
|
{
|
|
var sel3 = $"update [dbo].[T_PP_ORDERPLAN_PAOMO] set SCRAP_QTY = SCRAP_QTY + 1 where PLAN_NO = '{resObj.PlanID.Substring(0, 14)}'";
|
|
SqlData.InsertWare(sel3);
|
|
}
|
|
else if (resObj.Type == "2" && resObj.State == "3")
|
|
{
|
|
var sel3 = $"update [dbo].[T_PP_ORDERPLAN_ZHUSU] set REPAIR_QTY = REPAIR_QTY + 1 where PLAN_NO = '{resObj.PlanID.Substring(0, 14)}'";
|
|
SqlData.InsertWare(sel3);
|
|
}
|
|
else if (resObj.Type == "2" && resObj.State == "4")
|
|
{
|
|
var sel3 = $"update [dbo].[T_PP_ORDERPLAN_ZHUSU] set SCRAP_QTY = SCRAP_QTY + 1 where PLAN_NO = '{resObj.PlanID.Substring(0, 14)}'";
|
|
SqlData.InsertWare(sel3);
|
|
}
|
|
}
|
|
else
|
|
{
|
|
var ResponseNOK = new Response();
|
|
ResponseNOK.Code = 400;
|
|
ResponseNOK.Message = "禁止重复操作!";
|
|
return Ok(ResponseNOK);
|
|
}
|
|
}
|
|
|
|
var Response = new Response();
|
|
|
|
return Ok(Response);
|
|
}
|
|
|
|
|
|
}
|
|
}
|
|
|