| ¶Ô±ÈÐÂÎļþ |
| | |
| | | using System.Data; |
| | | using System.Dynamic; |
| | | using System.Text; |
| | | using Gs.Toolbox; |
| | | using Gs.Toolbox.ApiCore.Abstract.Mvc; |
| | | using Gs.Toolbox.ApiCore.Common.Mvc; |
| | | using Gs.Toolbox.ApiCore.Group; |
| | | using Microsoft.AspNetCore.Authorization; |
| | | using Microsoft.AspNetCore.Http; |
| | | using Microsoft.AspNetCore.Mvc; |
| | | using Newtonsoft.Json.Linq; |
| | | using static Gs.Toolbox.UtilityHelper; |
| | | |
| | | namespace Gs.Wom.WorkService |
| | | { |
| | | |
| | | [ApiGroup(ApiGroupNames.WOM)] |
| | | public class MesBackFlashController : IRomteService |
| | | { |
| | | private readonly IHttpContextAccessor _http; |
| | | private readonly string _userCode, _userGuid, _orgFids; |
| | | public MesBackFlashController(IHttpContextAccessor httpContextAccessor) |
| | | { |
| | | _http = httpContextAccessor; |
| | | (_userCode, _userGuid, _orgFids) = GetUserGuidAndOrgGuid(_http); |
| | | } |
| | | |
| | | #region |
| | | /// <summary> |
| | | /// 读ååè¡¨ï¼æ¯æå页 |
| | | /// </summary> |
| | | /// <param name="model"></param> |
| | | /// <returns></returns> |
| | | [RequestMethod(RequestMethods.POST)] |
| | | public ReturnDto<PageList<dynamic>> GetListPage([FromBody] PageQuery model) |
| | | { |
| | | int currentPage = model.currentPage; |
| | | int everyPageSize = model.everyPageSize; |
| | | string sortName = string.IsNullOrEmpty(model.sortName) ? "org.FNumber" : model.sortName; |
| | | string keyWhere = model.keyWhere; |
| | | System.Text.StringBuilder _w = new StringBuilder(); |
| | | _w.Append(" from [dbo].[MES_BACK_FLASH] a"); |
| | | _w.Append(" left join MES_ITEMS i on a.ItemID=i.item_id "); |
| | | _w.Append(" left join MES_DEPOTS d on a.depotId=d.depot_id "); |
| | | _w.Append(" left join SYS_DEPARTMENT m on a.departmentId=m.departmentid "); |
| | | _w.Append(" left join SYS_ORGANIZATION org on i.FSubsidiary=org.FID"); |
| | | _w.Append(" where 1=1 " + keyWhere); |
| | | System.Text.StringBuilder sbSql = new StringBuilder(); |
| | | sbSql.Append("select * from "); |
| | | sbSql.Append("( "); |
| | | sbSql.Append("select top 100000 ROW_NUMBER() over(order by " + sortName + " " + model.sortOrder + ") as rowIndex,a.*,'('+org.FNumber+')'+org.NAME as orgName "); |
| | | sbSql.Append(",i.item_no as itemNo,i.item_name as itemName,i.item_model as itemModel,d.depot_name as depotName,m.departmentname as bmName"); |
| | | sbSql.Append(_w); |
| | | sbSql.Append(") as T "); |
| | | sbSql.Append(" where T.rowindex>(" + currentPage + "-1)*" + everyPageSize + " and T.rowindex<=" + currentPage + "*" + everyPageSize); |
| | | sbSql.Append(" order by rowindex asc "); |
| | | sbSql.Append(" select count(1) as intTotal "); |
| | | sbSql.Append(_w); |
| | | DataSet dset = new DataSet(); |
| | | try |
| | | { |
| | | dset = Gs.Toolbox.DbHelperSQL.Query(sbSql.ToString()); |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | Gs.Toolbox.LogHelper.Debug(this.ToString(), "GetListPage errorï¼" + ex.Message); |
| | | return ReturnDto<PageList<dynamic>>.QuickReturn(default(PageList<dynamic>), ReturnCode.Exception, "读å失败"); |
| | | } |
| | | PageList<dynamic> _pglist = new PageList<dynamic> |
| | | { |
| | | total = 0, |
| | | everyPageSize = 0, |
| | | pages = 0, |
| | | list = new List<dynamic>() |
| | | }; |
| | | if (dset != null && dset.Tables.Count > 0 && dset.Tables[0].Rows.Count > 0)//ææ°æ® |
| | | { |
| | | int intTotal = int.Parse(dset.Tables[1].Rows[0]["intTotal"].ToString()); |
| | | int pages = (intTotal % everyPageSize != 0) ? (intTotal / everyPageSize + 1) : (intTotal / everyPageSize); |
| | | _pglist.total = intTotal; |
| | | _pglist.everyPageSize = everyPageSize; |
| | | _pglist.pages = pages; |
| | | List<dynamic> _dy = dset.Tables[0].TableToDynamicList(); |
| | | _pglist.list = _dy; |
| | | } |
| | | return ReturnDto<PageList<dynamic>>.QuickReturn(_pglist, ReturnCode.Success, "读åæå"); |
| | | } |
| | | |
| | | |
| | | /// <summary> |
| | | /// å é¤å®ä½ |
| | | /// </summary> |
| | | /// <param name="model"></param> |
| | | /// <returns></returns> |
| | | [RequestMethod(RequestMethods.POST)] |
| | | public ReturnDto<int?> DeleteModel([FromBody] JArray guidList) |
| | | { |
| | | var intArray = guidList.ToObject<string[]>(); |
| | | string guid = intArray[0]; |
| | | int rtnInt = (int)ReturnCode.Default; |
| | | int cont = 0; |
| | | try |
| | | { |
| | | cont = isChkOrUnChk(guid, 1); |
| | | if (cont > 0) |
| | | return ReturnDto<int>.QuickReturn(default(int?), ReturnCode.Exception, "å é¤å¤±è´¥ï¼è¯¥ä¿¡æ¯å·²è¢«å®¡æ ¸ï¼"); |
| | | StringBuilder strSql = new StringBuilder(); |
| | | strSql.Append(" delete from MES_BACK_FLASH "); |
| | | strSql.Append(" where guid='" + guid + "'"); |
| | | int rows = DbHelperSQL.ExecuteSql(strSql.ToString()); |
| | | rtnInt = rows; |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | LogHelper.Debug(this.ToString(), "DeleteModel errorï¼" + ex.Message); |
| | | rtnInt = (int)ReturnCode.Exception; |
| | | return ReturnDto<int>.QuickReturn(default(int?), ReturnCode.Exception, "å é¤å¤±è´¥ï¼" + ex.Message); |
| | | } |
| | | if (rtnInt > 0) |
| | | return ReturnDto<int>.QuickReturn(default(int?), ReturnCode.Success, "æä½æåï¼å
±å é¤" + rtnInt.ToString() + "æ¡æ°æ®ï¼"); |
| | | else |
| | | return ReturnDto<int>.QuickReturn(default(int?), ReturnCode.Exception, "å é¤å¤±è´¥ï¼è¯·éè¯ï¼"); |
| | | } |
| | | |
| | | /// <summary> |
| | | /// å¢å å®ä½ |
| | | /// </summary> |
| | | /// <param name="model"></param> |
| | | /// <returns></returns> |
| | | [RequestMethod(RequestMethods.POST)] |
| | | public ReturnDto<ExpandoObject> EditModel([FromBody] dynamic model) |
| | | { |
| | | string itemId = model.itemId; |
| | | string departmentId = model.departmentId; |
| | | string depotId = model.depotId; |
| | | int? rtnInt = (int)ReturnCode.Default; |
| | | dynamic mObj = new ExpandoObject(); |
| | | mObj.outMsg = ""; |
| | | mObj.outSum = -1; |
| | | mObj.outGuid = ""; |
| | | mObj.outNo = ""; |
| | | StringBuilder strSql = new StringBuilder(); |
| | | string guid = Guid.NewGuid().ToString(); |
| | | strSql.Append(" insert into MES_BACK_FLASH"); |
| | | strSql.Append(" ([guid] ,[ItemId] ,[departmentId] ,[depotId],createBy,createDate,checkStatus)"); |
| | | strSql.Append(" values("); |
| | | strSql.Append(" '" + guid + "','" + itemId + "','" + departmentId + "'," + depotId + ",'" + _userCode + "',getdate(),0)"); |
| | | try |
| | | { |
| | | rtnInt = DbHelperSQL.ExecuteSql(strSql.ToString()); |
| | | mObj.outMsg = "æä½æåï¼"; |
| | | mObj.outSum = rtnInt; |
| | | mObj.outGuid = guid; |
| | | mObj.outNo = itemId; |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | LogHelper.Debug(this.ToString(), "EditModel errorï¼" + ex.Message); |
| | | rtnInt = (int)ReturnCode.Exception; |
| | | mObj.outMsg = ex.Message; |
| | | mObj.outSum = -1; |
| | | } |
| | | if (mObj.outSum <= 0) |
| | | return ReturnDto<dynamic>.QuickReturn(mObj, ReturnCode.Exception, mObj.outMsg); |
| | | return ReturnDto<dynamic>.QuickReturn(mObj, ReturnCode.Success, mObj.outMsg); |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 读åå®ä½ |
| | | /// </summary> |
| | | /// <param name="guid"></param> |
| | | /// <returns></returns> |
| | | [RequestMethod(RequestMethods.POST)] |
| | | [AllowAnonymous] |
| | | public ReturnDto<System.Dynamic.ExpandoObject> GetModel([FromBody] dynamic model) |
| | | { |
| | | dynamic m = new System.Dynamic.ExpandoObject(); |
| | | System.Text.StringBuilder sbSql = new StringBuilder(); |
| | | sbSql.Append("select top 1 a.*,org.FID as orgId ,i.item_no as itemNo,i.item_name as itemName,i.item_model as itemModel from MES_BACK_FLASH a left join MES_ITEMS i on a.ItemID=i.item_id left join SYS_ORGANIZATION org on i.FSubsidiary=org.FID where 1=1 and a.guid='" + model.guid.ToString() + "' "); |
| | | try |
| | | { |
| | | DataSet dset = new DataSet(); |
| | | dset = DbHelperSQL.Query(sbSql.ToString()); |
| | | if (dset != null && dset.Tables.Count > 0 && dset.Tables[0].Rows.Count > 0) |
| | | { |
| | | System.Data.DataRow dr = dset.Tables[0].Rows[0]; |
| | | m = dr.RowToDynamic(); |
| | | return ReturnDto<dynamic>.QuickReturn(m, ReturnCode.Success, "读åæåï¼"); |
| | | } |
| | | else |
| | | return ReturnDto<dynamic>.QuickReturn(m, ReturnCode.Default, "读å失败ï¼"); |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | LogHelper.Debug(this.ToString(), "GetModel error:" + ex.Message); |
| | | return ReturnDto<dynamic>.QuickReturn(m, ReturnCode.Default, "读å失败ï¼"); |
| | | } |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 夿æ¯å¦å®¡æ ¸ |
| | | /// </summary> |
| | | /// <param name="guidList"></param> |
| | | /// <param name="status"></param> |
| | | /// <returns></returns> |
| | | private int isChkOrUnChk(string guidList, int status) |
| | | { |
| | | int cont = 0; |
| | | cont = int.Parse(DbHelperSQL.GetSingle("select count(1) from MES_BACK_FLASH where guid='" + guidList + "' and isnull(checkstatus,0)=" + status + "").ToString()); |
| | | return cont; |
| | | } |
| | | #endregion |
| | | } |
| | | } |