ouyangqing
2021-01-21 9d1960d3041695b470e0db44de914012ef3a8a2f
进出站单限制
3个文件已修改
128 ■■■■ 已修改文件
WebAPI/Controllers/NewApiController.cs 4 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
WebAPI/Service/YqnDal.cs 48 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
WebAPI/Service/YqnQbService.cs 76 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
WebAPI/Controllers/NewApiController.cs
@@ -17,9 +17,9 @@
        /// <returns></returns>
        [Route("api/newBill/getNewInterBillNo")]
        [HttpGet]
        public ApiResult<DocumentsView> GetNewInterBillNo()
        public ApiResult<DocumentsView> GetNewInterBillNo(string billType)
        {
            var model = YqnQbService.GetInterBillNo();
            var model = YqnQbService.GetInterBillNo(billType);
            return model;
        }
        /// <summary>
WebAPI/Service/YqnDal.cs
@@ -10,38 +10,58 @@
    public class YqnDal
    {
        /// <summary>
        /// 根据单据号或者流转卡查找进站单
        /// 根据工序和流转卡查找进站单
        /// </summary>
        /// <param name="billNo"></param>
        /// <param name="icmoBillNo"></param>
        /// <returns></returns>
        public static Models.M_StationBillMail GetStationInBillMail(string billNo, string icmoBillNo)
        public static Models.M_StationBillMail GetStationInBillMail(long hProcID, string icmoBillNo)
        {
            StringBuilder sqlBuilder = new StringBuilder();
            sqlBuilder.Append("select top 1 HBillType,HInterID,HDate,HBillNo,HICMOBillNo,HEmpID,HProcID from Sc_StationInBillMain where HBillType='3790' ");
            if (!string.IsNullOrEmpty(billNo))
                sqlBuilder.Append(" and HBillNo=@billNo ");
            if (!string.IsNullOrEmpty(icmoBillNo))
                sqlBuilder.Append(" and HICMOBillNo=@icmoBillNo");
            var model = SqlPools.GetInstance("YqnConn").GetModel<Models.M_StationBillMail>(sqlBuilder.ToString(), new { billNo, icmoBillNo });
            sqlBuilder.Append(" and HICMOBillNo=@icmoBillNo ");
            sqlBuilder.Append(" and HProcID=@hProcID");
            var model = SqlPools.GetInstance("YqnConn").GetModel<Models.M_StationBillMail>(sqlBuilder.ToString(), new {  icmoBillNo,hProcID });
            return model;
        }
        /// <summary>
        /// 根据单据号或者流转卡查找出站单
        /// 根据工序和流转卡查找出站单
        /// </summary>
        /// <param name="billNo"></param>
        /// <param name="icmoBillNo"></param>
        /// <returns></returns>
        public static Models.M_StationBillMail GetStationOutBillMail(string billNo, string icmoBillNo)
        public static Models.M_StationBillMail GetStationOutBillMail(long hProcID, string icmoBillNo)
        {
            StringBuilder sqlBuilder = new StringBuilder();
            sqlBuilder.Append("select top 1 HBillType,HInterID,HDate,HBillNo,HICMOBillNo,HEmpID,HProcID from Sc_StationOutBillMain where HBillType in ('3791','4788') ");
            if (!string.IsNullOrEmpty(billNo))
                sqlBuilder.Append(" and HBillNo=@billNo ");
            if (!string.IsNullOrEmpty(icmoBillNo))
                sqlBuilder.Append(" and HICMOBillNo=@icmoBillNo");
            var model = SqlPools.GetInstance("YqnConn").GetModel<Models.M_StationBillMail>(sqlBuilder.ToString(), new { billNo, icmoBillNo });
            sqlBuilder.Append(" and HICMOBillNo=@icmoBillNo ");
            sqlBuilder.Append(" and HProcID=@hProcID");
            var model = SqlPools.GetInstance("YqnConn").GetModel<Models.M_StationBillMail>(sqlBuilder.ToString(), new { icmoBillNo, hProcID });
            return model;
        }
        /// <summary>
        /// 根据流传卡号获取进站单列表
        /// </summary>
        /// <param name="icBillNo"></param>
        /// <returns></returns>
        public static List<Models.M_StationBillMail> GetStationInBillMailList(string icBillNo)
        {
            StringBuilder sqlBuilder = new StringBuilder();
            sqlBuilder.Append("select HBillType,HInterID,HDate,HBillNo,HICMOBillNo,HEmpID,HProcID from Sc_StationInBillMain where HBillType='3790' and HICMOBillNo=@icBillNo");
            var list = SqlPools.GetInstance("YqnConn").GetModelList<Models.M_StationBillMail>(sqlBuilder.ToString(), new { icBillNo });
            return list;
        }
        /// <summary>
        /// 根据流传卡号获取出站单列表
        /// </summary>
        /// <param name="icBillNo"></param>
        /// <returns></returns>
        public static List<Models.M_StationBillMail> GetStationOutBillMailList(string icBillNo)
        {
            StringBuilder sqlBuilder = new StringBuilder();
            sqlBuilder.Append("select HBillType,HInterID,HDate,HBillNo,HICMOBillNo,HEmpID,HProcID from Sc_StationOutBillMain where HBillType in ('3791','4788') and HICMOBillNo=@icBillNo");
            var list = SqlPools.GetInstance("YqnConn").GetModelList<Models.M_StationBillMail>(sqlBuilder.ToString(), new { icBillNo });
            return list;
        }
    }
}
WebAPI/Service/YqnQbService.cs
@@ -5,6 +5,7 @@
using System.Data;
using System.Linq;
using System.Web;
using WebAPI.Dapper;
using WebAPI.Models;
using WebAPI.WebS;
@@ -16,10 +17,10 @@
        /// 获取单据号
        /// </summary>
        /// <returns></returns>
        public static ApiResult<DocumentsView> GetInterBillNo()
        public static ApiResult<DocumentsView> GetInterBillNo(string billType)
        { 
            var hInterId= DBUtility.ClsPub.CreateBillID(ApiConfig.HBillType, ref DBUtility.ClsPub.sExeReturnInfo);
            var hBillNo= DBUtility.ClsPub.CreateBillCode(ApiConfig.HBillType, ref DBUtility.ClsPub.sExeReturnInfo, true);
            var hInterId= DBUtility.ClsPub.CreateBillID(billType, ref DBUtility.ClsPub.sExeReturnInfo);
            var hBillNo= DBUtility.ClsPub.CreateBillCode(billType, ref DBUtility.ClsPub.sExeReturnInfo, true);
            if (hInterId == 0 || string.IsNullOrEmpty(hBillNo))
                return new ApiResult<DocumentsView> { code = -1, msg = "获取失败" };
            DocumentsView documentsView = new DocumentsView()
@@ -84,20 +85,53 @@
                return new ApiResult<DataSet> { code = -1, msg = "未查询到工作中心" };
            return new ApiResult<DataSet> { code = 1, msg = "查询成功", data = dataSet };
        }
        private static ConcurrentDictionary<string, string> dicLock = new System.Collections.Concurrent.ConcurrentDictionary<string, string>();//并发锁
        /// <summary>
        /// 进站接收单
        /// </summary>
        public static ApiResult SetStationInBill(ClsSc_StationInBillMain oMain)
        {
            WebS.WebService1 oWebs = new WebS.WebService1();
            string sErrMsg = string.Empty;
            var result = oWebs.set_SaveStationInBill(oMain, ref  sErrMsg);
            if (!result)
            if (dicLock.TryAdd(oMain.HICMOBillNo + "jz", ""))//防止并发
                return new ApiResult { code = -1, msg = "服务器繁忙" };
            try
            {
                if (oMain.HProcID == 0 || oMain.HQty == 0 || oMain.HEmpID == 0||string.IsNullOrEmpty(oMain.HICMOBillNo)||string.IsNullOrEmpty(oMain.HProcExchBillNo)||oMain.HQty==0||oMain.HICMOInterID==0||string.IsNullOrEmpty(oMain.HBillNo))
                    return new ApiResult { code = 1, msg = "参数不全" };
                var stationInList = YqnDal.GetStationInBillMailList(oMain.HICMOBillNo);//获得该流转卡所有进站单
                if (stationInList.Count > 0)
                {
                    var stationOutList = YqnDal.GetStationOutBillMailList(oMain.HICMOBillNo);//获得该流转卡所有出站单
                    var stationInModel = stationInList.OrderByDescending(a => a.HDate).First();//获取进站单最新进站工序
                    if (stationOutList.Count == 0 && oMain.HEmpID == stationInModel.HEmpID)
                        return new ApiResult { code = -1, msg = "重复扫描" };
                    if (stationOutList.Count == 0 && oMain.HEmpID != stationInModel.HEmpID)
                        return new ApiResult { code = -1, msg = "此单已关联" };
                    var stationOutModel = stationOutList.OrderByDescending(a => a.HDate).First();//获取出站单最新出站工序
                    if (stationInModel.HProcID != stationOutModel.HProcID && stationInModel.HEmpID == oMain.HEmpID)
                        return new ApiResult { code = -1, msg = "重复扫描" };
                    if (stationInModel.HProcID != stationOutModel.HProcID && stationInModel.HEmpID == oMain.HEmpID)
                        return new ApiResult { code = -1, msg = "此单已关联" };
                    if (stationOutList.Exists(a => a.HProcID == oMain.HProcID))
                        return new ApiResult { code = -1, msg = "该单据已完成此工艺" };
                }
                WebS.WebService1 oWebs = new WebS.WebService1();
                string sErrMsg = string.Empty;
                var result = oWebs.set_SaveStationInBill(oMain, ref sErrMsg);//进站
                if (!result)
                {
                return new ApiResult { code = -1, msg = sErrMsg };
                    return new ApiResult { code = -1, msg = sErrMsg };
                }
                return new ApiResult { code = 1, msg = "操作成功" };
            }
            return new ApiResult { code = 1, msg = "操作成功" };
            catch (Exception ex)
            {
                throw;
            }
            finally
            {
                dicLock.TryRemove(oMain.HICMOBillNo + "jz", out string key);
            }
        }
        /// <summary>
        /// 获取进站单列表
@@ -128,6 +162,14 @@
        /// </summary>
        public static ApiResult SetStationOutBill(StationOutBillView omodel)
        {
            if (!dicLock.TryAdd(omodel.HBillNo, omodel.HBillNo))
                return new ApiResult { code = -1, msg = "服务器繁忙" };
            var stationInBillModel = YqnDal.GetStationInBillMail(omodel.HProcID, omodel.HICMOBillNo);
            if (stationInBillModel == null)
                return new ApiResult { code = -1, msg = "该工序进站单不存在" };
            var stationOutBillModel = YqnDal.GetStationOutBillMail(omodel.HProcID, omodel.HICMOBillNo);
            if (stationOutBillModel != null)
                return new ApiResult { code = -1, msg = "该工序已存在出站单" };
            WebS.WebService1 oWebs = new WebS.WebService1();
            string sErrMsg = string.Empty;
            var result = SetOutBill(omodel);
@@ -184,17 +226,14 @@
            var dataSet = oCN.RunProcReturn("Select HItemID,HNumber 工作中心代码,HName 工作中心 from Gy_Group where HStopflag=0 " + sWhere + " Order by HItemID ", "Gy_Source");
            return dataSet;
        }
        private static ConcurrentDictionary<string,string> dicLock=new System.Collections.Concurrent.ConcurrentDictionary<string,string>();//并发锁
        public static ApiResult SetOutBill(StationOutBillView omodel)
        {
            try
            {
                if (!dicLock.TryAdd(omodel.HBillNo, omodel.HBillNo))
                    return new ApiResult { code = -1, msg = "服务器繁忙" };
                SQLHelper.ClsCN oCN = new SQLHelper.ClsCN();
                omodel.HInterID = DBUtility.ClsPub.CreateBillID("4788", ref DBUtility.ClsPub.sExeReturnInfo);
                omodel.HInterID = DBUtility.ClsPub.CreateBillID("3791", ref DBUtility.ClsPub.sExeReturnInfo);
                oCN.BeginTran();
                var sql = "Insert Into Sc_StationOutBillMain " +
                oCN.RunProc("Insert Into Sc_StationOutBillMain " +
                    "(HBillType,HBillSubType,HInterID,HBillNo,HBillStatus,HDate,HMaker,HMakeDate" +
                    ",HYear,HPeriod,HRemark" +
                    ",HICMOInterID,HICMOBillNo,HProcPlanInterID,HProcPlanEntryID,HProcPlanBillNo,HProcExchInterID,HProcExchEntryID" +
@@ -202,24 +241,19 @@
                    ",HGroupID,HDeptID,HEmpID,HBarCode,HAddr,HBarCodeMaker,HBarCodeMakeDate" +
                    ",HSupID,HQty,HPrice,HMoney" +
                    ") " +
                    " values('4788','4788'," + omodel.HInterID.ToString() + ",'" + omodel.HBillNo + "'," + omodel.HBillStatus.ToString() + ",getdate(),'" + DBUtility.ClsPub.CurUserName + "',getdate()" +
                    " values('3791','3791'," + omodel.HInterID.ToString() + ",'" + omodel.HBillNo + "'," + omodel.HBillStatus.ToString() + ",getdate(),'" + DBUtility.ClsPub.CurUserName + "',getdate()" +
                    "," + omodel.HYear.ToString() + "," + omodel.HPeriod.ToString() + ",'" + omodel.HRemark + "'" +
                    "," + omodel.HICMOInterID.ToString() + ",'" + omodel.HICMOBillNo + "'," + omodel.HProcPlanInterID.ToString() + "," + omodel.HProcPlanEntryID.ToString() + ",'" + omodel.HProcPlanBillNo + "'," + omodel.HProcExchInterID.ToString() + "," + omodel.HProcExchEntryID.ToString() +
                    ",'" + omodel.HProcExchBillNo + "'," + omodel.HMaterID.ToString() + "," + omodel.HProcID.ToString() + "," + omodel.HICMOQty.ToString() + "," + omodel.HPlanQty.ToString() + ",getdate()," + omodel.HSourceID.ToString() +
                    "," + omodel.HGroupID.ToString() + "," + omodel.HDeptID.ToString() + "," + omodel.HEmpID.ToString() + ",'" + omodel.HBarCode + "','" + omodel.HAddr + "','" + omodel.HBarCodeMaker + "',getdate()" +
                    "," + omodel.HSupID.ToString() + "," + omodel.HQty.ToString() + "," + omodel.HPrice.ToString() + "," + omodel.HMoney.ToString() +
                  ") ";
                oCN.RunProc(sql);
                  ") ");
                oCN.Commit();
                return new ApiResult { code = 1, msg = "新增成功" };
            }
            catch (Exception ex)
            {
                return new ApiResult { code = -1, msg = "保存错误/"+ex.ToString() };
            }
            finally
            {
                dicLock.TryRemove(omodel.HBillNo, out string key);
            }
        }
        public static ApiResult SetInBill(ClsSc_StationInBillMain omodel)