SchoolMakerStudyController.cs 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386
  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. return View();
  80. }
  81. #endregion
  82. #region 增加商学院创客学堂
  83. /// <summary>
  84. /// 增加或修改商学院创客学堂信息
  85. /// </summary>
  86. /// <returns></returns>
  87. [HttpPost]
  88. public string Add(SchoolMakerStudy data, string PColId = "", string CurColId = "")
  89. {
  90. Dictionary<string, object> Fields = new Dictionary<string, object>();
  91. Fields.Add("Title", data.Title); //标题
  92. Fields.Add("Detail", data.Detail); //介绍
  93. Fields.Add("ListPic", data.ListPic); //列表图片
  94. Fields.Add("Contents", data.Contents); //内容
  95. Fields.Add("QueryCount", data.QueryCount); //学习人数
  96. Fields.Add("Url", data.Url); //外链
  97. Fields.Add("SeoTitle", data.SeoTitle);
  98. Fields.Add("SeoKeyword", data.SeoKeyword);
  99. Fields.Add("SeoDescription", data.SeoDescription);
  100. int Id = new AdminContentOther(_accessor.HttpContext, PublicFunction.MainTables).Add("SchoolMakerStudy", Fields, 0);
  101. AddSysLog(data.Id.ToString(), "SchoolMakerStudy", "add");
  102. db.SaveChanges();
  103. return "success";
  104. }
  105. #endregion
  106. #region 修改商学院创客学堂
  107. /// <summary>
  108. /// 增加或修改商学院创客学堂信息
  109. /// </summary>
  110. /// <returns></returns>
  111. public IActionResult Edit(string right, string ColId, string PColId, string CurColId, int Id = 0)
  112. {
  113. ViewBag.RightInfo = RightInfo;
  114. ViewBag.right = right;
  115. SchoolMakerStudy editData = db.SchoolMakerStudy.FirstOrDefault(m => m.Id == Id) ?? new SchoolMakerStudy();
  116. ViewBag.data = editData;
  117. return View();
  118. }
  119. #endregion
  120. #region 修改商学院创客学堂
  121. /// <summary>
  122. /// 增加或修改商学院创客学堂信息
  123. /// </summary>
  124. /// <returns></returns>
  125. [HttpPost]
  126. public string Edit(SchoolMakerStudy data, string PColId = "", string CurColId = "")
  127. {
  128. Dictionary<string, object> Fields = new Dictionary<string, object>();
  129. Fields.Add("Title", data.Title); //标题
  130. Fields.Add("Detail", data.Detail); //介绍
  131. Fields.Add("SeoTitle", data.SeoTitle); //主讲人
  132. Fields.Add("QueryCount", data.QueryCount); //观看人数
  133. Fields.Add("ListPic", data.ListPic); //列表图片
  134. Fields.Add("Contents", data.Contents); //内容
  135. Fields.Add("Url", data.Url); //外链
  136. Fields.Add("SeoKeyword", data.SeoKeyword);
  137. Fields.Add("SeoDescription", data.SeoDescription);
  138. new AdminContentOther(_accessor.HttpContext, PublicFunction.MainTables).Edit("SchoolMakerStudy", Fields, data.Id);
  139. AddSysLog(data.Id.ToString(), "SchoolMakerStudy", "update");
  140. db.SaveChanges();
  141. return "success";
  142. }
  143. #endregion
  144. #region 删除商学院创客学堂信息
  145. /// <summary>
  146. /// 删除商学院创客学堂信息
  147. /// </summary>
  148. /// <returns></returns>
  149. public string Delete(string Id)
  150. {
  151. string[] idlist = Id.Split(new char[] { ',' });
  152. AddSysLog(Id, "SchoolMakerStudy", "del");
  153. foreach (string subid in idlist)
  154. {
  155. int id = int.Parse(subid);
  156. Dictionary<string, object> Fields = new Dictionary<string, object>();
  157. Fields.Add("Status", -1);
  158. new AdminContentOther(_accessor.HttpContext, PublicFunction.MainTables).Edit("SchoolMakerStudy", Fields, id);
  159. }
  160. db.SaveChanges();
  161. return "success";
  162. }
  163. #endregion
  164. #region 开启
  165. /// <summary>
  166. /// 开启
  167. /// </summary>
  168. /// <returns></returns>
  169. public string Open(string Id)
  170. {
  171. string[] idlist = Id.Split(new char[] { ',' });
  172. AddSysLog(Id, "SchoolMakerStudy", "open");
  173. foreach (string subid in idlist)
  174. {
  175. int id = int.Parse(subid);
  176. Dictionary<string, object> Fields = new Dictionary<string, object>();
  177. Fields.Add("Status", 1);
  178. new AdminContentOther(_accessor.HttpContext, PublicFunction.MainTables).Edit("SchoolMakerStudy", Fields, id);
  179. }
  180. db.SaveChanges();
  181. return "success";
  182. }
  183. #endregion
  184. #region 关闭
  185. /// <summary>
  186. /// 关闭
  187. /// </summary>
  188. /// <returns></returns>
  189. public string Close(string Id)
  190. {
  191. string[] idlist = Id.Split(new char[] { ',' });
  192. AddSysLog(Id, "SchoolMakerStudy", "close");
  193. foreach (string subid in idlist)
  194. {
  195. int id = int.Parse(subid);
  196. Dictionary<string, object> Fields = new Dictionary<string, object>();
  197. Fields.Add("Status", 0);
  198. new AdminContentOther(_accessor.HttpContext, PublicFunction.MainTables).Edit("SchoolMakerStudy", Fields, id);
  199. }
  200. db.SaveChanges();
  201. return "success";
  202. }
  203. #endregion
  204. #region 排序
  205. /// <summary>
  206. /// 排序
  207. /// </summary>
  208. /// <param name="Id"></param>
  209. public string Sort(int Id, int Sort)
  210. {
  211. new AdminContentOther(_accessor.HttpContext, PublicFunction.MainTables).Sort("SchoolMakerStudy", Sort, Id);
  212. AddSysLog(Id.ToString(), "SchoolMakerStudy", "sort");
  213. return "success";
  214. }
  215. #endregion
  216. #region 导入数据
  217. /// <summary>
  218. /// 导入数据
  219. /// </summary>
  220. /// <param name="ExcelData"></param>
  221. public string Import(string ExcelData)
  222. {
  223. ExcelData = HttpUtility.UrlDecode(ExcelData);
  224. JsonData list = JsonMapper.ToObject(ExcelData);
  225. var error = "";
  226. for (int i = 1; i < list.Count; i++)
  227. {
  228. JsonData dr = list[i];
  229. string MakerCode = dr[0].ToString(); // 创客编号
  230. string Auths = dr[1].ToString(); // 权限
  231. string[] Auth = Auths.Split(',');
  232. var fAuth = "";
  233. var userForMakerCode = db.UserForMakerCode.FirstOrDefault(m => m.MakerCode == MakerCode) ?? new UserForMakerCode();
  234. var userInfo = db.Users.FirstOrDefault(m => m.Id == userForMakerCode.UserId) ?? new Users();
  235. var time = 0;
  236. if (userInfo.Id == 0)
  237. {
  238. error += "创客" + MakerCode + "不存在" + '\n';
  239. }
  240. foreach (var item in Auth)
  241. {
  242. var col = bsdb.Col.FirstOrDefault(m => m.ColId == item) ?? new BsModels.Col();
  243. if (col.Id == 0)
  244. {
  245. error += "权限编号" + item + "不存在" + '\n';
  246. }
  247. else
  248. {
  249. time += 1;
  250. if (time == 1)
  251. {
  252. fAuth += "," + item + ",";
  253. }
  254. else
  255. {
  256. fAuth += item + ",";
  257. }
  258. }
  259. }
  260. if (!string.IsNullOrEmpty(error))
  261. {
  262. return "Warning|" + error;
  263. }
  264. var check = db.UserCardRecord.Any(m => m.Id == userInfo.Id);
  265. if (check)
  266. {
  267. var auth = db.UserCardRecord.FirstOrDefault(m => m.Id == userInfo.Id) ?? new UserCardRecord();
  268. foreach (var item in Auth)
  269. {
  270. if (!auth.SeoDescription.Contains("," + item + ","))
  271. {
  272. auth.SeoDescription += item + ",";
  273. }
  274. }
  275. auth.UpdateDate = DateTime.Now;
  276. auth.UpdateMan = SysUserName + "-" + SysRealName;
  277. db.SaveChanges();
  278. }
  279. else
  280. {
  281. var query = db.UserCardRecord.Add(new UserCardRecord()
  282. {
  283. Id = userInfo.Id,
  284. CreateDate = DateTime.Now, //创建时间
  285. CreateMan = SysUserName + "-" + SysRealName,
  286. SeoDescription = fAuth,
  287. }).Entity;
  288. db.SaveChanges();
  289. }
  290. }
  291. db.SaveChanges();
  292. AddSysLog("0", "SchoolMakerStudy", "Import");
  293. return "success";
  294. }
  295. #endregion
  296. #region 导出Excel
  297. /// <summary>
  298. /// 导出Excel
  299. /// </summary>
  300. /// <returns></returns>
  301. public JsonResult ExportExcel(SchoolMakerStudy data)
  302. {
  303. Dictionary<string, string> Fields = new Dictionary<string, string>();
  304. Fields.Add("Title", "1"); //标题
  305. Fields.Add("CreateDate", "3"); //时间
  306. string condition = " and Status>-1";
  307. Dictionary<string, object> obj = new AdminContentOther(_accessor.HttpContext, PublicFunction.MainTables).IndexData("SchoolMakerStudy", Fields, "Id desc", "0", 1, 20000, condition, "", false);
  308. List<Dictionary<string, object>> diclist = obj["data"] as List<Dictionary<string, object>>;
  309. foreach (Dictionary<string, object> dic in diclist)
  310. {
  311. dic["StatusName"] = dic["Status"].ToString() == "1" ? "正常" : "关闭";
  312. }
  313. Dictionary<string, object> result = new Dictionary<string, object>();
  314. result.Add("Status", "1");
  315. result.Add("Info", "Excel报表-" + DateTime.Now.ToString("yyyy-MM-ddTHH:mm:ss") + ".xlsx");
  316. result.Add("Obj", diclist);
  317. Dictionary<string, object> ReturnFields = new Dictionary<string, object>();
  318. result.Add("Fields", ReturnFields);
  319. AddSysLog("0", "SchoolMakerStudy", "ExportExcel");
  320. return Json(result);
  321. }
  322. #endregion
  323. }
  324. }