Нет описания

ApplicationsVersionController.cs 12KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306
  1. using CallCenter.Utility;
  2. using CallCenterApi.DB;
  3. using CallCenterApi.Interface.Controllers.Base;
  4. using System;
  5. using System.Collections.Generic;
  6. using System.Data;
  7. using System.IO;
  8. using System.Linq;
  9. using System.Web;
  10. using System.Web.Mvc;
  11. namespace CallCenterApi.Interface.Controllers
  12. {
  13. public class ApplicationsVersionController : BaseController
  14. {
  15. private BLL.T_Sys_ApplicationsVersion ApplicationsBLL = new BLL.T_Sys_ApplicationsVersion();
  16. public class ApplicationsVersion
  17. {
  18. public int F_ID { get; set; }
  19. public int F_Type { get; set; }//应用分类(0android 1ios)
  20. public string F_VersionName { get; set; }//版本名称
  21. public string F_VersionCode { get; set; }//版本号
  22. public string F_Files { get; set; }//附件id
  23. public string F_Url { get; set; }//ios链接地址
  24. public int F_Sort { get; set; }//F_Sort
  25. public string F_Remarks { get; set; }//F_Remarks
  26. public DataTable FileUrl { get; set; }//android链接地址
  27. }
  28. /// <summary>
  29. /// 添加
  30. /// </summary>
  31. /// <param name="input"></param>
  32. /// <returns></returns>
  33. [HttpPost]
  34. public ActionResult Add(ApplicationsVersion input)
  35. {
  36. if (Request.IsAuthenticated)
  37. {
  38. int userId = CurrentUser.UserData.F_UserId;
  39. Model.T_Sys_UserAccount userModel = new BLL.T_Sys_UserAccount().GetModel(userId);
  40. Model.T_Sys_ApplicationsVersion dModel = new Model.T_Sys_ApplicationsVersion();
  41. dModel.F_Type = input.F_Type;
  42. dModel.F_VersionName = input.F_VersionName;
  43. dModel.F_VersionCode = input.F_VersionCode;
  44. dModel.F_Files = input.F_Files;
  45. dModel.F_Url = input.F_Url;
  46. dModel.F_Remarks = input.F_Remarks;
  47. dModel.F_Sort = input.F_Sort;
  48. dModel.F_CreateTime = DateTime.Now;
  49. if (userModel != null)
  50. dModel.F_CreateUser = userModel.F_UserCode;
  51. dModel.F_IsDelete = 0;
  52. if (input.F_ID > 0)
  53. {
  54. dModel.F_ID = input.F_ID;
  55. bool id = ApplicationsBLL.Update (dModel);
  56. if (id )
  57. {
  58. return Success("修改成功");
  59. }
  60. else
  61. return Success("修改失败");
  62. }
  63. else
  64. {
  65. int id = ApplicationsBLL.Add(dModel);
  66. if (id > 0)
  67. {
  68. return Success("添加成功");
  69. }
  70. else
  71. return Success("添加失败");
  72. }
  73. }
  74. return NoToken("未知错误,请重新登录");
  75. }
  76. /// <summary>
  77. /// 删除
  78. /// </summary>
  79. /// <param name="ids"></param>
  80. /// <returns></returns>
  81. public ActionResult DelApp(string[] ids)
  82. {
  83. if (Request.IsAuthenticated)
  84. {
  85. if (ids == null || ids.Length <= 0)
  86. return Error("请选择要删除的设备");
  87. var idStr = string.Join(",", ids);
  88. if (string.IsNullOrEmpty(idStr.Trim()))
  89. return Error("请选择要删除的设备");
  90. if (ApplicationsBLL.DeleteList(idStr))
  91. return Success("删除成功");
  92. return Error("删除失败");
  93. }
  94. return NoToken("未知错误,请重新登录");
  95. }
  96. public ActionResult GetIos()
  97. {
  98. var configfj = new BLL.T_Sys_SystemConfig().GetModelList(" F_ParamCode='FileUrlPath' ").FirstOrDefault();
  99. var model = new BLL.T_Sys_ApplicationsVersion().GetModelList("F_IsDelete=0 and F_Type=1 order by F_ID DESC ").FirstOrDefault();
  100. if (model != null)
  101. {
  102. ApplicationsVersion app = new ApplicationsVersion();
  103. app.F_ID = model.F_ID;
  104. app.F_Type = (int)model.F_Type;
  105. app.F_VersionName = model.F_VersionName;
  106. app.F_VersionCode = model.F_VersionCode;
  107. app.F_Files = model.F_Files;
  108. app.F_Url = model.F_Url;
  109. app.F_Sort = (int)model.F_Sort;
  110. app.F_Remarks = model.F_Remarks;
  111. app.FileUrl = GetFileData(model.F_Files, configfj.F_ParamValue);
  112. return Success("成功", app);
  113. }
  114. return Error("获取失败");
  115. }
  116. public ActionResult GetAndroid()
  117. {
  118. var configfj = new BLL.T_Sys_SystemConfig().GetModelList(" F_ParamCode='FileUrlPath' ").FirstOrDefault();
  119. var model = new BLL.T_Sys_ApplicationsVersion().GetModelList("F_IsDelete=0 and F_Type=0 order by F_ID DESC ").FirstOrDefault();
  120. if (model != null)
  121. {
  122. ApplicationsVersion app = new ApplicationsVersion();
  123. app.F_ID = model.F_ID;
  124. app.F_Type = (int)model.F_Type;
  125. app.F_VersionName = model.F_VersionName;
  126. app.F_VersionCode = model.F_VersionCode;
  127. app.F_Files = model.F_Files;
  128. app.F_Url = model.F_Url;
  129. app.F_Sort = (int)model.F_Sort;
  130. app.F_Remarks = model.F_Remarks;
  131. app.FileUrl = GetFileData(model.F_Files, configfj.F_ParamValue);
  132. return Success("成功", app);
  133. }
  134. return Error("获取失败");
  135. }
  136. /// <summary>
  137. /// 列表
  138. /// </summary>
  139. /// <returns></returns>
  140. public ActionResult GetList(string keywords, int pageindex = 1, int pagesize = 10)
  141. {
  142. DataTable dt = new DataTable();
  143. string sql = "and F_IsDelete=0";
  144. if (!string.IsNullOrWhiteSpace(keywords))//关键字搜索
  145. sql += $" and ( F_VersionName like '%" + keywords.Trim() + "%'or F_Type like '%" + keywords.Trim() + "%'or F_VersionCode like '%" + keywords.Trim() + "%' ) ";
  146. int recordCount = 0;
  147. if (!string.IsNullOrWhiteSpace(sql))
  148. {
  149. dt = BLL.PagerBLL.GetListPager(
  150. "T_Sys_ApplicationsVersion",
  151. "F_ID",
  152. "*",
  153. sql,
  154. "ORDER BY T_Sys_ApplicationsVersion.F_ID desc,F_Sort asc",
  155. pagesize,
  156. pageindex,
  157. true,
  158. out recordCount);
  159. }
  160. List<Model.T_Sys_ApplicationsVersion> modlelist = new BLL.T_Sys_ApplicationsVersion().DataTableToList(dt);
  161. if (modlelist.Count > 0)
  162. {
  163. var obj = new
  164. {
  165. state = "success",
  166. message = "成功",
  167. rows = modeltoip(modlelist),
  168. total = recordCount
  169. };
  170. return Content(obj.ToJson()); ;
  171. }
  172. else
  173. {
  174. return Success("暂无数据"); ;
  175. }
  176. }
  177. public DataTable GetFileData(string ids, string prefix)
  178. {
  179. DataTable dt = new DataTable();
  180. if (!string.IsNullOrEmpty(ids))
  181. {
  182. dt = DbHelperSQL.Query("select * from T_Sys_Accessories where F_Id in (" + ids + ")").Tables[0];
  183. foreach (DataRow dr in dt.Rows)
  184. {
  185. dr["F_Url"] = prefix + dr["F_Url"].ToString();
  186. }
  187. }
  188. return dt;
  189. }
  190. private List <ApplicationsVersion> modeltoip(List<Model.T_Sys_ApplicationsVersion >t_Sys_ApplicationsVersion )
  191. {
  192. var configfj = new BLL.T_Sys_SystemConfig().GetModelList(" F_ParamCode='FileUrlPath' ").FirstOrDefault();
  193. List<ApplicationsVersion> model = new List<ApplicationsVersion>();
  194. if (t_Sys_ApplicationsVersion!=null )
  195. {
  196. foreach (var it in t_Sys_ApplicationsVersion)
  197. {
  198. ApplicationsVersion app = new ApplicationsVersion();
  199. app.F_ID = it.F_ID;
  200. app.F_Type =(int ) it.F_Type;
  201. app.F_VersionName = it.F_VersionName;
  202. app.F_VersionCode = it.F_VersionCode;
  203. app.F_Files = it.F_Files;
  204. app.F_Url = it.F_Url;
  205. app.F_Sort = (int )it.F_Sort;
  206. app.F_Remarks = it.F_Remarks;
  207. app.FileUrl = GetFileData(it.F_Files, configfj.F_ParamValue);
  208. model.Add(app);
  209. }
  210. }
  211. return model;
  212. }
  213. /// <summary>
  214. /// 查询详情
  215. /// </summary>
  216. public ActionResult GetDetails(int id)
  217. {
  218. int userId = CurrentUser.UserData.F_UserId;
  219. if (userId != 0)
  220. {
  221. DataTable FileUrl = new DataTable();
  222. Model.T_Sys_UserAccount ua = new BLL.T_Sys_UserAccount().GetModel(userId);
  223. if (id <= 0)
  224. {
  225. return Error("请输入正确的id");
  226. }
  227. var model = ApplicationsBLL.GetModel(id);
  228. if (model == null)
  229. return Error("该应用不存在");
  230. List<Model.T_Sys_ApplicationsVersion> modlelist = new List<Model.T_Sys_ApplicationsVersion>();
  231. modlelist.Add(model);
  232. var obj = new
  233. {
  234. state = "success",
  235. message = "成功",
  236. rows = modeltoip(modlelist),
  237. };
  238. return Content(obj.ToJson());
  239. }
  240. else
  241. {
  242. return Error("无操作权限!");
  243. }
  244. }
  245. private BLL.T_Sys_UserAccount userBLL = new BLL.T_Sys_UserAccount();
  246. /// <summary>
  247. /// 上传附件
  248. /// </summary>
  249. /// <returns></returns>
  250. public ActionResult UploadFile()
  251. {
  252. int userId = CurrentUser.UserData.F_UserId;
  253. Model.T_Sys_UserAccount userModel = userBLL.GetModel(userId);
  254. #region 多个上传
  255. HttpFileCollection files = RequestString.GetFiles();
  256. if (files.Count > 0)
  257. {
  258. List<Model.T_Sys_Accessories> acs = new List<Model.T_Sys_Accessories>();
  259. string path = "/Upload/Files/" + DateTime.Now.ToString("yyyy") + "/" + DateTime.Now.ToString("MM") + "/" + DateTime.Now.ToString("dd") + "/";
  260. for (int i = 0; i < files.Count; i++)
  261. {
  262. HttpPostedFile file = files[i];
  263. FileUp fu = new FileUp();
  264. string name = fu.Upload(file, path);
  265. Model.T_Sys_Accessories model_T_Sys_Accessories = new Model.T_Sys_Accessories();
  266. model_T_Sys_Accessories.F_CreateTime = DateTime.Now;//上传时间
  267. model_T_Sys_Accessories.F_Name = file.FileName;//附件名称
  268. model_T_Sys_Accessories.F_Type = System.IO.Path.GetExtension(file.FileName);//附件类型
  269. model_T_Sys_Accessories.F_Url = path + name;//附件地址
  270. model_T_Sys_Accessories.F_Size = file.ContentLength;
  271. model_T_Sys_Accessories.F_CreateUser = userModel.F_UserCode;//上传人
  272. int id = new BLL.T_Sys_Accessories().Add(model_T_Sys_Accessories);
  273. model_T_Sys_Accessories.F_Id = id;
  274. acs.Add(model_T_Sys_Accessories);
  275. }
  276. return Success("成功", acs);
  277. }
  278. else
  279. {
  280. return Error("请选择要上传的文件");
  281. }
  282. #endregion
  283. }
  284. }
  285. }