¶Ô±ÈÐÂÎļþ |
| | |
| | | using Gs.Toolbox; |
| | | using Microsoft.AspNetCore.Authorization; |
| | | using Microsoft.AspNetCore.Mvc; |
| | | using System; |
| | | using System.Collections.Generic; |
| | | using System.Data.SqlClient; |
| | | using System.Data; |
| | | using System.Linq; |
| | | using System.Text; |
| | | using System.Threading.Tasks; |
| | | using Gs.User.Modes; |
| | | |
| | | namespace Gs.User.Service |
| | | { |
| | | [ApiGroup(ApiGroupNames.Auth)] |
| | | public class MenuActionController : IRomteService |
| | | { |
| | | |
| | | /// <summary> |
| | | /// 读ååè½èååè¡¨ï¼æ¯æå页 |
| | | /// </summary> |
| | | /// <param name="model"></param> |
| | | /// <returns></returns> |
| | | [RequestMethod(RequestMethods.POST)] |
| | | public ReturnDto<PageList<MenuAction>> GetListPage([FromBody] PageQuery model) |
| | | { |
| | | int currentPage = model.currentPage; |
| | | int everyPageSize = model.everyPageSize; |
| | | string sortName = string.IsNullOrEmpty(model.sortName) ? "a.idx" : model.sortName; |
| | | 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,* from sys_MenuAction a where 1=1" + model.keyWhere); |
| | | sbSql.Append(") as T "); |
| | | sbSql.Append(" where T.rowindex>(" + currentPage + "-1)*" + everyPageSize + " and T.rowindex<=" + currentPage + "*" + everyPageSize + ""); |
| | | sbSql.Append(" select count(1) as intTotal from dbo.sys_MenuAction a where 1=1 " + model.keyWhere).ToString(); |
| | | 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<MenuAction>>.QuickReturn(default(PageList<MenuAction>), ReturnCode.Exception, "读å失败"); |
| | | } |
| | | PageList<MenuAction> _pglist = new PageList<MenuAction> |
| | | { |
| | | total = 0, |
| | | everyPageSize = 0, |
| | | pages = 0, |
| | | list = new List<MenuAction>() |
| | | }; |
| | | 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; |
| | | foreach (DataRow dr in dset.Tables[0].Rows) |
| | | { |
| | | _pglist.list.Add( |
| | | new MenuAction() |
| | | { |
| | | guid = Guid.Parse(dr["guid"].ToString()), |
| | | upGuid = dr["upGuid"].ToString().Length > 0 ? Guid.Parse(dr["upGuid"].ToString()) : null, |
| | | name = dr["name"].ToString(), |
| | | serialNumber = dr["serialNumber"].ToString(), |
| | | icon = dr["icon"].ToString(), |
| | | status = int.Parse(dr["status"].ToString()), |
| | | fromPath = dr["fromPath"].ToString(), |
| | | idx = int.Parse(dr["idx"].ToString()), |
| | | category = int.Parse(dr["category"].ToString()), |
| | | } |
| | | ); |
| | | } |
| | | } |
| | | return ReturnDto<PageList<MenuAction>>.QuickReturn(_pglist, ReturnCode.Success, "读åæå"); |
| | | } |
| | | |
| | | |
| | | /// <summary> |
| | | /// å é¤åè½èå |
| | | /// </summary> |
| | | /// <param name="model"></param> |
| | | /// <returns></returns> |
| | | [RequestMethod(RequestMethods.POST)] |
| | | public ReturnDto<int?> DeleteModel([FromBody] MenuAction model) |
| | | { |
| | | int rtnInt = (int)ReturnCode.Default; |
| | | try |
| | | { |
| | | rtnInt = DbHelperSQL.ExecuteSql("delete from dbo.sys_MenuAction where guid='" + model.guid.ToString() + "'"); |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | LogHelper.Debug(this.ToString(), "DeleteModel errorï¼" + ex.Message); |
| | | rtnInt = (int)ReturnCode.Exception; |
| | | } |
| | | 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<int?> EditModel([FromBody] MenuAction model) |
| | | { |
| | | string dddd= model.guid.ToString(); |
| | | Guid? guid = model.guid; |
| | | Guid? upGuid = model.upGuid; |
| | | string name = model.name; |
| | | string serialNumber = model.serialNumber; |
| | | string icon = model.icon; |
| | | int status = model.status; |
| | | string fromPath = model.fromPath; |
| | | int category = model.category; |
| | | int idx = model.idx; |
| | | int? rtnInt = (int)ReturnCode.Default; |
| | | StringBuilder strSql = new StringBuilder(); |
| | | if (guid != null) |
| | | { |
| | | strSql.Append(" update dbo.sys_MenuAction"); |
| | | strSql.Append(" set upGuid=@upGuid,name=@name,serialNumber=@serialNumber,icon=@icon,status=@status,fromPath=@fromPath,category=@category,idx=@idx"); |
| | | strSql.Append(" where guid='" + guid + "'"); |
| | | } |
| | | else |
| | | { |
| | | guid = Guid.NewGuid(); |
| | | strSql.Append("insert into dbo.sys_MenuAction("); |
| | | strSql.Append(" guid,upGuid,name,serialNumber,icon,status,fromPath,category,idx)"); |
| | | strSql.Append(" values ("); |
| | | strSql.Append("'" + guid + "',@upGuid,@name,@serialNumber,@icon,@status,@fromPath,@category,@idx)"); |
| | | } |
| | | SqlParameter[] parameters = { |
| | | new SqlParameter("@upGuid", upGuid), |
| | | new SqlParameter("@name", name), |
| | | new SqlParameter("@serialNumber",serialNumber), |
| | | new SqlParameter("@icon",icon), |
| | | new SqlParameter("@status",status), |
| | | new SqlParameter("@fromPath",fromPath), |
| | | new SqlParameter("@category",category), |
| | | new SqlParameter("@idx",idx), |
| | | }; |
| | | try |
| | | { |
| | | rtnInt = DbHelperSQL.ExecuteSql(strSql.ToString(), parameters); |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | LogHelper.Debug(this.ToString(), "EditModel errorï¼" + ex.Message); |
| | | rtnInt = (int)ReturnCode.Exception; |
| | | } |
| | | if (rtnInt > 0) |
| | | return ReturnDto<int>.QuickReturn(rtnInt, ReturnCode.Success, "å¢å æåï¼"); |
| | | else |
| | | return ReturnDto<int>.QuickReturn(rtnInt, ReturnCode.Exception, "å¢å 失败ï¼è¯·éè¯ï¼"); |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 读ååè½èå |
| | | /// </summary> |
| | | /// <param name="guid"></param> |
| | | /// <returns></returns> |
| | | [RequestMethod(RequestMethods.POST)] |
| | | [AllowAnonymous] |
| | | public ReturnDto<MenuAction> GetModel([FromBody] MenuAction model ) |
| | | { |
| | | MenuAction m = new MenuAction(); |
| | | System.Text.StringBuilder sbSql = new StringBuilder(); |
| | | sbSql.Append("select top 1 * from dbo.sys_MenuAction where 1=1 and 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.guid = Guid.Parse(dr["guid"].ToString()); |
| | | m.upGuid = dr["upGuid"].ToString().Length > 0 ? Guid.Parse(dr["upGuid"].ToString()) : null; |
| | | m.name = dr["name"].ToString(); |
| | | m.serialNumber = dr["serialNumber"].ToString(); |
| | | m.icon = dr["icon"].ToString(); |
| | | m.status = int.Parse(dr["status"].ToString()); |
| | | m.fromPath = dr["fromPath"].ToString(); |
| | | m.idx = int.Parse(dr["idx"].ToString()); |
| | | m.category = int.Parse(dr["category"].ToString()); |
| | | 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, "读å失败ï¼"); |
| | | } |
| | | } |
| | | } |
| | | } |