SchoolMakerStudyController.cs 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404
  1. /*
  2. * 商学院创客学堂
  3. */
  4. using System;
  5. using System.Web;
  6. using System.Collections.Generic;
  7. using System.Diagnostics;
  8. using System.Linq;
  9. using System.Threading.Tasks;
  10. using Microsoft.AspNetCore.Mvc;
  11. using Microsoft.AspNetCore.Http;
  12. using Microsoft.Extensions.Logging;
  13. using Microsoft.Extensions.Options;
  14. using MySystem.Models;
  15. using Library;
  16. using LitJson;
  17. using MySystemLib;
  18. namespace MySystem.Areas.Admin.Controllers
  19. {
  20. [Area("Admin")]
  21. [Route("Admin/[controller]/[action]")]
  22. public class SchoolMakerStudyController : BaseController
  23. {
  24. public SchoolMakerStudyController(IHttpContextAccessor accessor, ILogger<BaseController> logger, IOptions<Setting> setting) : base(accessor, logger, setting)
  25. {
  26. OtherMySqlConn.connstr = ConfigurationManager.AppSettings["SqlConnStr"].ToString();
  27. }
  28. #region 商学院创客学堂列表
  29. /// <summary>
  30. /// 根据条件查询商学院创客学堂列表
  31. /// </summary>
  32. /// <returns></returns>
  33. public IActionResult Index(SchoolMakerStudy data, string right)
  34. {
  35. ViewBag.RightInfo = RightInfo;
  36. ViewBag.right = right;
  37. return View();
  38. }
  39. #endregion
  40. #region 根据条件查询商学院创客学堂列表
  41. /// <summary>
  42. /// 商学院创客学堂列表
  43. /// </summary>
  44. /// <returns></returns>
  45. public JsonResult IndexData(SchoolMakerStudy data, int page = 1, int limit = 30)
  46. {
  47. Dictionary<string, string> Fields = new Dictionary<string, string>();
  48. Fields.Add("Title", "1"); //标题
  49. Fields.Add("CreateDate", "3"); //时间
  50. string condition = " and Status>-1";
  51. if (!string.IsNullOrEmpty(data.SeoKeyword))
  52. {
  53. condition += " and SeoKeyword like '" + data.SeoKeyword + "%'";
  54. }
  55. Dictionary<string, object> obj = new AdminContentOther(_accessor.HttpContext, PublicFunction.MainTables).IndexData("SchoolMakerStudy", Fields, "Id desc", "0", page, limit, condition);
  56. List<Dictionary<string, object>> diclist = obj["data"] as List<Dictionary<string, object>>;
  57. foreach (Dictionary<string, object> dic in diclist)
  58. {
  59. dic["StatusName"] = dic["Status"].ToString() == "1" ? "正常" : "关闭";
  60. }
  61. return Json(obj);
  62. }
  63. #endregion
  64. #region 增加商学院创客学堂
  65. /// <summary>
  66. /// 增加或修改商学院创客学堂信息
  67. /// </summary>
  68. /// <returns></returns>
  69. public IActionResult Add(string right, string PColId, string CurColId)
  70. {
  71. ViewBag.RightInfo = RightInfo;
  72. ViewBag.right = right;
  73. ViewBag.CurColId = CurColId;
  74. if (string.IsNullOrEmpty(PColId))
  75. {
  76. PColId = "001";
  77. }
  78. ViewBag.PColId = PColId;
  79. // string code = "";
  80. // int len = PColId.Length + 3;
  81. // Col model = bsdb.Col.Where(m => m.ColId.StartsWith(PColId) && m.ColId.Length == len).OrderByDescending(m => m.ColId).FirstOrDefault();
  82. // if (model != null)
  83. // {
  84. // string CurCode = model.ColId;
  85. // int num = int.Parse(CurCode.Substring(CurCode.Length - 3)) + 1;
  86. // code = num.ToString();
  87. // for (int i = 0; i < 3 - num.ToString().Length; i++)
  88. // {
  89. // code = "0" + code;
  90. // }
  91. // code = PColId + code;
  92. // }
  93. // else
  94. // {
  95. // code = PColId + "001";
  96. // }
  97. return View();
  98. }
  99. #endregion
  100. #region 增加商学院创客学堂
  101. /// <summary>
  102. /// 增加或修改商学院创客学堂信息
  103. /// </summary>
  104. /// <returns></returns>
  105. [HttpPost]
  106. public string Add(SchoolMakerStudy data, string PColId = "", string CurColId = "")
  107. {
  108. Dictionary<string, object> Fields = new Dictionary<string, object>();
  109. Fields.Add("Title", data.Title); //标题
  110. Fields.Add("Detail", data.Detail); //介绍
  111. Fields.Add("ListPic", data.ListPic); //列表图片
  112. Fields.Add("Contents", data.Contents); //内容
  113. Fields.Add("QueryCount", data.QueryCount); //学习人数
  114. Fields.Add("Url", data.Url); //外链
  115. Fields.Add("SeoTitle", data.SeoTitle);
  116. Fields.Add("SeoKeyword", data.SeoKeyword);
  117. Fields.Add("SeoDescription", data.SeoDescription);
  118. int Id = new AdminContentOther(_accessor.HttpContext, PublicFunction.MainTables).Add("SchoolMakerStudy", Fields, 0);
  119. AddSysLog(data.Id.ToString(), "SchoolMakerStudy", "add");
  120. db.SaveChanges();
  121. return "success";
  122. }
  123. #endregion
  124. #region 修改商学院创客学堂
  125. /// <summary>
  126. /// 增加或修改商学院创客学堂信息
  127. /// </summary>
  128. /// <returns></returns>
  129. public IActionResult Edit(string right, string ColId, string PColId, string CurColId, int Id = 0)
  130. {
  131. ViewBag.RightInfo = RightInfo;
  132. ViewBag.right = right;
  133. SchoolMakerStudy editData = db.SchoolMakerStudy.FirstOrDefault(m => m.Id == Id) ?? new SchoolMakerStudy();
  134. ViewBag.data = editData;
  135. return View();
  136. }
  137. #endregion
  138. #region 修改商学院创客学堂
  139. /// <summary>
  140. /// 增加或修改商学院创客学堂信息
  141. /// </summary>
  142. /// <returns></returns>
  143. [HttpPost]
  144. public string Edit(SchoolMakerStudy data, string PColId = "", string CurColId = "")
  145. {
  146. Dictionary<string, object> Fields = new Dictionary<string, object>();
  147. Fields.Add("Title", data.Title); //标题
  148. Fields.Add("Detail", data.Detail); //介绍
  149. Fields.Add("SeoTitle", data.SeoTitle); //主讲人
  150. Fields.Add("QueryCount", data.QueryCount); //观看人数
  151. Fields.Add("ListPic", data.ListPic); //列表图片
  152. Fields.Add("Contents", data.Contents); //内容
  153. Fields.Add("Url", data.Url); //外链
  154. Fields.Add("SeoKeyword", data.SeoKeyword);
  155. Fields.Add("SeoDescription", data.SeoDescription);
  156. new AdminContentOther(_accessor.HttpContext, PublicFunction.MainTables).Edit("SchoolMakerStudy", Fields, data.Id);
  157. AddSysLog(data.Id.ToString(), "SchoolMakerStudy", "update");
  158. db.SaveChanges();
  159. return "success";
  160. }
  161. #endregion
  162. #region 删除商学院创客学堂信息
  163. /// <summary>
  164. /// 删除商学院创客学堂信息
  165. /// </summary>
  166. /// <returns></returns>
  167. public string Delete(string Id)
  168. {
  169. string[] idlist = Id.Split(new char[] { ',' });
  170. AddSysLog(Id, "SchoolMakerStudy", "del");
  171. foreach (string subid in idlist)
  172. {
  173. int id = int.Parse(subid);
  174. Dictionary<string, object> Fields = new Dictionary<string, object>();
  175. Fields.Add("Status", -1);
  176. new AdminContentOther(_accessor.HttpContext, PublicFunction.MainTables).Edit("SchoolMakerStudy", Fields, id);
  177. }
  178. db.SaveChanges();
  179. return "success";
  180. }
  181. #endregion
  182. #region 开启
  183. /// <summary>
  184. /// 开启
  185. /// </summary>
  186. /// <returns></returns>
  187. public string Open(string Id)
  188. {
  189. string[] idlist = Id.Split(new char[] { ',' });
  190. AddSysLog(Id, "SchoolMakerStudy", "open");
  191. foreach (string subid in idlist)
  192. {
  193. int id = int.Parse(subid);
  194. Dictionary<string, object> Fields = new Dictionary<string, object>();
  195. Fields.Add("Status", 1);
  196. new AdminContentOther(_accessor.HttpContext, PublicFunction.MainTables).Edit("SchoolMakerStudy", Fields, id);
  197. }
  198. db.SaveChanges();
  199. return "success";
  200. }
  201. #endregion
  202. #region 关闭
  203. /// <summary>
  204. /// 关闭
  205. /// </summary>
  206. /// <returns></returns>
  207. public string Close(string Id)
  208. {
  209. string[] idlist = Id.Split(new char[] { ',' });
  210. AddSysLog(Id, "SchoolMakerStudy", "close");
  211. foreach (string subid in idlist)
  212. {
  213. int id = int.Parse(subid);
  214. Dictionary<string, object> Fields = new Dictionary<string, object>();
  215. Fields.Add("Status", 0);
  216. new AdminContentOther(_accessor.HttpContext, PublicFunction.MainTables).Edit("SchoolMakerStudy", Fields, id);
  217. }
  218. db.SaveChanges();
  219. return "success";
  220. }
  221. #endregion
  222. #region 排序
  223. /// <summary>
  224. /// 排序
  225. /// </summary>
  226. /// <param name="Id"></param>
  227. public string Sort(int Id, int Sort)
  228. {
  229. new AdminContentOther(_accessor.HttpContext, PublicFunction.MainTables).Sort("SchoolMakerStudy", Sort, Id);
  230. AddSysLog(Id.ToString(), "SchoolMakerStudy", "sort");
  231. return "success";
  232. }
  233. #endregion
  234. #region 导入数据
  235. /// <summary>
  236. /// 导入数据
  237. /// </summary>
  238. /// <param name="ExcelData"></param>
  239. public string Import(string ExcelData)
  240. {
  241. ExcelData = HttpUtility.UrlDecode(ExcelData);
  242. JsonData list = JsonMapper.ToObject(ExcelData);
  243. var error = "";
  244. for (int i = 1; i < list.Count; i++)
  245. {
  246. JsonData dr = list[i];
  247. string MakerCode = dr[0].ToString(); // 创客编号
  248. string Auths = dr[1].ToString(); // 权限
  249. string[] Auth = Auths.Split(',');
  250. var fAuth = "";
  251. var userForMakerCode = db.UserForMakerCode.FirstOrDefault(m => m.MakerCode == MakerCode) ?? new UserForMakerCode();
  252. var userInfo = db.Users.FirstOrDefault(m => m.Id == userForMakerCode.UserId) ?? new Users();
  253. var time = 0;
  254. if (userInfo.Id == 0)
  255. {
  256. error += "创客" + MakerCode + "不存在" + '\n';
  257. }
  258. foreach (var item in Auth)
  259. {
  260. var col = bsdb.Col.FirstOrDefault(m => m.ColId == item) ?? new BsModels.Col();
  261. if (col.Id == 0)
  262. {
  263. error += "权限编号" + item + "不存在" + '\n';
  264. }
  265. else
  266. {
  267. time += 1;
  268. if (time == 1)
  269. {
  270. fAuth += "," + item + ",";
  271. }
  272. else
  273. {
  274. fAuth += item + ",";
  275. }
  276. }
  277. }
  278. if (!string.IsNullOrEmpty(error))
  279. {
  280. return "Warning|" + error;
  281. }
  282. var check = db.UserCardRecord.Any(m => m.Id == userInfo.Id);
  283. if (check)
  284. {
  285. var auth = db.UserCardRecord.FirstOrDefault(m => m.Id == userInfo.Id) ?? new UserCardRecord();
  286. foreach (var item in Auth)
  287. {
  288. if (!auth.SeoDescription.Contains("," + item + ","))
  289. {
  290. auth.SeoDescription += item + ",";
  291. }
  292. }
  293. auth.UpdateDate = DateTime.Now;
  294. auth.UpdateMan = SysUserName + "-" + SysRealName;
  295. db.SaveChanges();
  296. }
  297. else
  298. {
  299. var query = db.UserCardRecord.Add(new UserCardRecord()
  300. {
  301. Id = userInfo.Id,
  302. CreateDate = DateTime.Now, //创建时间
  303. CreateMan = SysUserName + "-" + SysRealName,
  304. SeoDescription = fAuth,
  305. }).Entity;
  306. db.SaveChanges();
  307. }
  308. }
  309. db.SaveChanges();
  310. AddSysLog("0", "SchoolMakerStudy", "Import");
  311. return "success";
  312. }
  313. #endregion
  314. #region 导出Excel
  315. /// <summary>
  316. /// 导出Excel
  317. /// </summary>
  318. /// <returns></returns>
  319. public JsonResult ExportExcel(SchoolMakerStudy data)
  320. {
  321. Dictionary<string, string> Fields = new Dictionary<string, string>();
  322. Fields.Add("Title", "1"); //标题
  323. Fields.Add("CreateDate", "3"); //时间
  324. string condition = " and Status>-1";
  325. Dictionary<string, object> obj = new AdminContentOther(_accessor.HttpContext, PublicFunction.MainTables).IndexData("SchoolMakerStudy", Fields, "Id desc", "0", 1, 20000, condition, "", false);
  326. List<Dictionary<string, object>> diclist = obj["data"] as List<Dictionary<string, object>>;
  327. foreach (Dictionary<string, object> dic in diclist)
  328. {
  329. dic["StatusName"] = dic["Status"].ToString() == "1" ? "正常" : "关闭";
  330. }
  331. Dictionary<string, object> result = new Dictionary<string, object>();
  332. result.Add("Status", "1");
  333. result.Add("Info", "Excel报表-" + DateTime.Now.ToString("yyyy-MM-ddTHH:mm:ss") + ".xlsx");
  334. result.Add("Obj", diclist);
  335. Dictionary<string, object> ReturnFields = new Dictionary<string, object>();
  336. result.Add("Fields", ReturnFields);
  337. AddSysLog("0", "SchoolMakerStudy", "ExportExcel");
  338. return Json(result);
  339. }
  340. #endregion
  341. }
  342. }