123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424 |
- using JCSoft.WX.Framework.Api;
- using Microsoft.AspNetCore.Mvc;
- using Microsoft.AspNetCore.Http;
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Threading.Tasks;
- using Common.Wechat;
- using Common;
- using System.Data;
- using Common.Model;
- using ZcPeng.PublicLibrary;
- using CoreEntity.Entity;
- using CoreEntity.DAL;
- using System.Collections.Concurrent;
- using Newtonsoft.Json.Converters;
- using Newtonsoft.Json;
- using System.Data.SqlClient;
- using Microsoft.Extensions.Primitives;
- using Microsoft.Extensions.Caching.Memory;
- using Jwt;
- using PublicLibrary.Model;
- using Newtonsoft.Json.Linq;
- using SupplierWeb.Codes.mvc;
- using SupplierWeb.Codes.Auth;
- using Common.Config;
- namespace SupplierWeb.Controllers
- {
- [Route("web/Mem_Terminaldoc")]
- public class Mem_TerminaldocController : BaseController
- {
- public Mem_TerminaldocController(IMemoryCache cache, IApiClient client) : base(cache, client)
- {
- }
- private ConcurrentDictionary<int, Mem_Terminaldoc> Mem_TerminaldocMap = new ConcurrentDictionary<int, Mem_Terminaldoc>();
- /// <summary>
- /// 获取平台终端列表
- /// </summary>
- /// <param name="filters"></param>
- /// <param name="pageIndex"></param>
- /// <param name="pageSize"></param>
- /// <param name="sortField"></param>
- /// <param name="sortDirection"></param>
- /// <param name="sumFields"></param>
- /// <param name="data"></param>
- /// <returns></returns>
- [AuthPermission]
- [HttpPost, Route("index")]
- public JsonResult Indexp(QueryFilter[] filters, Int32 pageIndex, Int32 pageSize,
- string sortField, Int32 sortDirection, string[] sumFields, [FromBody]dynamic data)
- {
- if (data != null)
- {
- filters = data.filters.ToObject<QueryFilter[]>();
- pageIndex = data.pageIndex;
- pageSize = data.pageSize;
- sortField = data.sortField;
- sortDirection = data.sortDirection;
- sumFields = data.sumFields.ToObject<string[]>();
- }
- #region 获取列表
- DataTable dt = new DataTable();
- string result;
- IList<Mem_Terminaldoc> permss = new List<Mem_Terminaldoc>(0);
- List<SqlParameter> parameters = new List<SqlParameter>();
- string filterstr = QueryFilter.getFilterSqlParam(filters, out parameters, new Mem_Terminaldoc(), "A.");
- string direct = " desc ";
- if (sortDirection != 1)
- {
- direct = " asc";
- }
- int start = (pageIndex - 1) * pageSize;
- int end = (start + 1 + pageSize);
- string commandText0 = "select * from ";
- string commandText1 = "(" +
- "select A.*,row_number() over" +
- "( order by A.TerminalKey " + direct + " ) as rownum from " +
- "Mem_Terminaldoc as A " +
- " where 1=1 " +
- filterstr +
- ")AAA ";
- string commandText2 = " where AAA.rownum>" + start + " and AAA.rownum<" + end
- + " ORDER BY AAA.TerminalKey desc";
- string commandText3 = commandText0 + commandText1 + commandText2;
- bool success = DataAccess.GetValues(commandText3, ref dt, parameters.ToArray(), out result);
- #endregion
- if (dt != null && dt.Rows.Count > 0)
- {
- // 把DataTable转换为IList<T>
- permss = ModelConvertHelper<Mem_Terminaldoc>.ConvertToModel(dt);
- }
- string result1;
- long totalcount = DataAccess.GetRowCountDefine("select count(TerminalKey) from " + commandText1, parameters.ToArray(), out result1);
- IsoDateTimeConverter timejson = new IsoDateTimeConverter
- {
- DateTimeFormat = "yyyy'-'MM'-'dd' 'HH':'mm':'ss"
- };
- //IList<Menu> menus = Permission.Convert(permss);
- var jsonData = JsonConvert.SerializeObject(permss, timejson);
- return Json(new
- {
- items = JsonConvert.DeserializeObject(jsonData),
- sum = new { },
- totalCount = totalcount
- });
- }
- /// <summary>
- /// 平台终端列表添加
- /// </summary>
- /// <param name="TerminalKey"></param>
- /// <param name="TerminalName"></param>
- /// <param name="TerminalDesc"></param>
- /// <param name="ParentTerminalKey"></param>
- /// <param name="TerminalCode"></param>
- /// <param name="HasLowLevel"></param>
- /// <param name="SourceTerminalCode"></param>
- /// <param name="SourceTerminalKey"></param>
- /// <param name="data"></param>
- /// <returns></returns>
- [AuthPermission]
- [HttpPost, Route("add")]
- public JsonResult Add(
- Int32 TerminalKey, string TerminalName, string TerminalDesc,
- Int32 ParentTerminalKey, Int32 TerminalCode,int HasLowLevel,
- Int32 SourceTerminalCode, string SourceTerminalKey, [FromBody]dynamic data
- )
- {
- if (data != null)
- {
- if (data.TerminalKey != null) { TerminalKey = data.TerminalKey; } else { TerminalKey = 0; }
- if (data.TerminalName != null) { TerminalName = data.TerminalName; } else { TerminalName = ""; }
- if (data.TerminalDesc != null) { TerminalDesc = data.TerminalDesc; } else { TerminalDesc = ""; }
- if (data.ParentTerminalKey != null) { ParentTerminalKey = data.ParentTerminalKey; } else { ParentTerminalKey = 0; }
- if (data.TerminalCode != null) { TerminalCode = data.TerminalCode; } else { TerminalCode = 0; }
- if (data.HasLowLevel != null) { HasLowLevel = data.HasLowLevel; } else { HasLowLevel =0; }
- if (data.SourceTerminalCode != null) { SourceTerminalCode = data.SourceTerminalCode; } else { SourceTerminalCode = 0; }
- if (data.SourceTerminalKey != null) { SourceTerminalKey = data.SourceTerminalKey; } else { SourceTerminalKey = ""; }
-
- }
- #region 添加机构节点
- //String uuid = System.Guid.NewGuid().ToString("N");
- int newid =Convert.ToInt32(ReturnMaxID("TerminalKey", "Mem_Terminaldoc"))+1;
- string commandText = "INSERT INTO Mem_Terminaldoc (TerminalKey," +
- "TerminalName,TerminalDesc,ParentTerminalKey,TerminalCode,HasLowLevel," +
- "SourceTerminalCode,SourceTerminalKey)" +
- " VALUES ('"+ newid + "',@TerminalName,@TerminalDesc,@ParentTerminalKey,@TerminalCode," +
- "@HasLowLevel,@SourceTerminalCode,@SourceTerminalKey)";
-
- string result;
- //string result1;
- //准备参数
- List<List<Object>> parameters = new List<List<Object>>();
- //parameters.Add(new List<Object>() { "TerminalKey", TerminalKey });
- parameters.Add(new List<Object>() { "TerminalName", TerminalName });
- parameters.Add(new List<Object>() { "TerminalDesc", TerminalDesc });
- parameters.Add(new List<Object>() { "ParentTerminalKey", ParentTerminalKey });
- parameters.Add(new List<Object>() { "TerminalCode", TerminalCode });
- parameters.Add(new List<Object>() { "HasLowLevel", HasLowLevel });
- parameters.Add(new List<Object>() { "SourceTerminalCode", SourceTerminalCode });
- parameters.Add(new List<Object>() { "SourceTerminalKey", SourceTerminalKey });
-
- List<SqlParameter> parameters1 = DataAccess.ToParameters(parameters);
- int success = DataAccess.ExecuteCommand(commandText, parameters1, out result);
- #endregion
- return Json(new
- {
- //success = success,success1
- success = success
- });
- }
- /// <summary>
- /// 平台终端列表修改
- /// </summary>
- /// <param name="TerminalKey"></param>
- /// <param name="TerminalName"></param>
- /// <param name="TerminalDesc"></param>
- /// <param name="ParentTerminalKey"></param>
- /// <param name="TerminalCode"></param>
- /// <param name="HasLowLevel"></param>
- /// <param name="SourceTerminalCode"></param>
- /// <param name="SourceTerminalKey"></param>
- /// <param name="data"></param>
- /// <returns></returns>
- [AuthPermission]
- [HttpPost, Route("edit")]
- public JsonResult edit(
- Int32 TerminalKey, string TerminalName, string TerminalDesc,
- Int32 ParentTerminalKey, Int32 TerminalCode, int HasLowLevel,
- Int32 SourceTerminalCode, string SourceTerminalKey, [FromBody]dynamic data
- )
- {
- if (data != null)
- {
- if (data.TerminalKey != null) { TerminalKey = data.TerminalKey; } else { TerminalKey = 0; }
- if (data.TerminalName != null) { TerminalName = data.TerminalName; } else { TerminalName = ""; }
- if (data.TerminalDesc != null) { TerminalDesc = data.TerminalDesc; } else { TerminalDesc = ""; }
- if (data.ParentTerminalKey != null) { ParentTerminalKey = data.ParentTerminalKey; } else { ParentTerminalKey = 0; }
- if (data.TerminalCode != null) { TerminalCode = data.TerminalCode; } else { TerminalCode = 0; }
- if (data.HasLowLevel != null) { HasLowLevel = data.HasLowLevel; } else { HasLowLevel = 0; }
- if (data.SourceTerminalCode != null) { SourceTerminalCode = data.SourceTerminalCode; } else { SourceTerminalCode = 0; }
- if (data.SourceTerminalKey != null) { SourceTerminalKey = data.SourceTerminalKey; } else { SourceTerminalKey = ""; }
- }
- //string[] RoleIdss = RoleId.Split(",");
- //int[] RoleIdis = Array.ConvertAll(RoleIdss, s => Convert.ToInt32(s));
- #region 编辑用户
- string commandText = "UPDATE Mem_Terminaldoc " +
- " SET TerminalName = @TerminalName,";
- commandText += " TerminalDesc = @TerminalDesc" +
- ",ParentTerminalKey = @ParentTerminalKey" +
- " ,TerminalCode = @TerminalCode" +
- ",HasLowLevel = @HasLowLevel" +
- ",SourceTerminalCode = @SourceTerminalCode" +
- ",SourceTerminalKey = @SourceTerminalKey" +
- " WHERE TerminalKey= @TerminalKey";
- string result;
- //准备参数
- List<List<Object>> parameters = new List<List<Object>>();
- parameters.Add(new List<Object>() { "TerminalKey", TerminalKey });
- parameters.Add(new List<Object>() { "TerminalName", TerminalName });
- parameters.Add(new List<Object>() { "TerminalDesc", TerminalDesc });
- parameters.Add(new List<Object>() { "ParentTerminalKey", ParentTerminalKey });
- parameters.Add(new List<Object>() { "TerminalCode", TerminalCode });
- parameters.Add(new List<Object>() { "HasLowLevel", HasLowLevel });
- parameters.Add(new List<Object>() { "SourceTerminalCode", SourceTerminalCode });
- parameters.Add(new List<Object>() { "SourceTerminalKey", SourceTerminalKey });
- List<SqlParameter> parameters1 = DataAccess.ToParameters(parameters);
- int success = DataAccess.ExecuteCommand(commandText, parameters1, out result);
- #endregion
- #region 角色
- //RoleDAL.SaveRolesRelatePermission(OrgId, RoleIdis);
- #endregion
- return Json(new
- {
- success = success,
- result = result,
- });
- }
- /// <summary>
- /// 组织机构删除
- /// </summary>
- /// <param name="id"></param>
- /// <returns></returns>
- [AuthPermission]
- [HttpPost, Route("delete")]
- public ActionResult Delete(string id)
- {
- //SQL语句
- string commandText = "DELETE FROM Mem_Terminaldoc WHERE TerminalKey = @id";
- //string commandText1 = "DELETE FROM Mem_TerminaldocRole WHERE TerminalKey = @id";
- //准备参数
- List<List<Object>> parameters = new List<List<Object>>();
- parameters.Add(new List<Object>() { "id", id });
- string result = "";
- //string result1 = "";
- //参数转换
- List<SqlParameter> parameters1 = DataAccess.ToParameters(parameters);
- //执行并返回结果
- int success = DataAccess.ExecuteCommand(commandText, parameters1, out result);
- //int success1 = DataAccess.ExecuteCommand(commandText1, parameters1, out result1);
- //如果Mem_Terminaldoc和Mem_TerminaldocRole表记录都删除成功
- int success2 = 0;
- if (success > 0 )
- {
- success2 = success;//此处应该是success2 = success+success1,由于不清楚前端是怎么接收处理的,暂且这么处理。
- }
- else
- {
- success2 = -1;
- }
- return Content("{success:" + success2 + "}");
- }
- /// <summary>
- /// 获取最大的id
- /// </summary>
- /// <param name="field"></param>
- /// <param name="tablename"></param>
- /// <returns></returns>
- public object ReturnMaxID(string field,string tablename)
- {
- string result;
- List<SqlParameter> parameters = new List<SqlParameter>();
- bool boolen = DataAccess.GetOneValue("select max("+ field + ") from "+ tablename, parameters.ToArray(), out object objValue, out result);
- if (boolen == true)
- {
- return objValue;
- }
- else
- {
- return result;
- }
- }
- [HttpGet]
- [Route("getterms")]
- public ActionResult getTerms()
- {
- IList<Option> options = new List<Option>();
- IList<Mem_Terminaldoc> terms = TerminalDAL.getTerms();
- foreach(var term in terms)
- {
- var option = new Option() { label = term.TerminalName,
- value = term.TerminalCode.ToString(), disabled = false };
- options.Add(option);
- }
- var jsonData = JsonConvert.SerializeObject(options);
- return Content(jsonData
- );
- }
- [HttpGet]
- [Route("getgender")]
- public ActionResult getgender()
- {
- IList<Option> options = new List<Option>();
- IList<Mem_Terminaldoc> terms = TerminalDAL.getTerms();
- var option = new Option()
- {
- label = "男",
- value = "1",
- disabled = false
- };
- options.Add(option);
- var option1 = new Option()
- {
- label = "女",
- value = "0",
- disabled = false
- };
- options.Add(option1);
- var option2 = new Option()
- {
- label = "未知",
- value = "2",
- disabled = false
- };
- options.Add(option2);
- var option3 = new Option()
- {
- label = "空",
- value = "",
- disabled = false
- };
- options.Add(option3);
- var option4 = new Option()
- {
- label = "空",
- value = " ",
- disabled = false
- };
- options.Add(option4);
- var jsonData = JsonConvert.SerializeObject(options);
- return Content(jsonData
- );
- }
- [HttpGet]
- [Route("getSourcePlatForms")]
- public ActionResult getSourcePlatForms()
- {
- IList<Option> options = new List<Option>();
- IList<Mem_DataDictory> terms = Mem_DataDictoryDAL.getDatas(" and parentid= '783' ");
- foreach (var term in terms)
- {
- var option = new Option()
- {
- label = term.Text,
- value = term.Value.ToString(),
- disabled = term.IsHide?true:false
- };
- options.Add(option);
- }
- var jsonData = JsonConvert.SerializeObject(options);
- return Content(jsonData
- );
- }
- }
- }
|