| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306 |
- using CallCenter.Utility;
- using CallCenterApi.DB;
- using CallCenterApi.Interface.Controllers.Base;
- using System;
- using System.Collections.Generic;
- using System.Data;
- using System.IO;
- using System.Linq;
- using System.Web;
- using System.Web.Mvc;
- namespace CallCenterApi.Interface.Controllers
- {
- public class ApplicationsVersionController : BaseController
- {
- private BLL.T_Sys_ApplicationsVersion ApplicationsBLL = new BLL.T_Sys_ApplicationsVersion();
- public class ApplicationsVersion
- {
- public int F_ID { get; set; }
- public int F_Type { get; set; }//应用分类(0android 1ios)
- public string F_VersionName { get; set; }//版本名称
- public string F_VersionCode { get; set; }//版本号
- public string F_Files { get; set; }//附件id
- public string F_Url { get; set; }//ios链接地址
- public int F_Sort { get; set; }//F_Sort
- public string F_Remarks { get; set; }//F_Remarks
- public DataTable FileUrl { get; set; }//android链接地址
- }
- /// <summary>
- /// 添加
- /// </summary>
- /// <param name="input"></param>
- /// <returns></returns>
- [HttpPost]
- public ActionResult Add(ApplicationsVersion input)
- {
- if (Request.IsAuthenticated)
- {
-
- int userId = CurrentUser.UserData.F_UserId;
- Model.T_Sys_UserAccount userModel = new BLL.T_Sys_UserAccount().GetModel(userId);
- Model.T_Sys_ApplicationsVersion dModel = new Model.T_Sys_ApplicationsVersion();
- dModel.F_Type = input.F_Type;
- dModel.F_VersionName = input.F_VersionName;
- dModel.F_VersionCode = input.F_VersionCode;
- dModel.F_Files = input.F_Files;
- dModel.F_Url = input.F_Url;
- dModel.F_Remarks = input.F_Remarks;
- dModel.F_Sort = input.F_Sort;
- dModel.F_CreateTime = DateTime.Now;
- if (userModel != null)
- dModel.F_CreateUser = userModel.F_UserCode;
- dModel.F_IsDelete = 0;
- if (input.F_ID > 0)
- {
- dModel.F_ID = input.F_ID;
- bool id = ApplicationsBLL.Update (dModel);
- if (id )
- {
- return Success("修改成功");
- }
- else
- return Success("修改失败");
- }
- else
- {
- int id = ApplicationsBLL.Add(dModel);
- if (id > 0)
- {
- return Success("添加成功");
- }
- else
- return Success("添加失败");
- }
-
- }
- return NoToken("未知错误,请重新登录");
- }
- /// <summary>
- /// 删除
- /// </summary>
- /// <param name="ids"></param>
- /// <returns></returns>
- public ActionResult DelApp(string[] ids)
- {
- if (Request.IsAuthenticated)
- {
- if (ids == null || ids.Length <= 0)
- return Error("请选择要删除的设备");
- var idStr = string.Join(",", ids);
- if (string.IsNullOrEmpty(idStr.Trim()))
- return Error("请选择要删除的设备");
- if (ApplicationsBLL.DeleteList(idStr))
- return Success("删除成功");
- return Error("删除失败");
- }
- return NoToken("未知错误,请重新登录");
- }
- public ActionResult GetIos()
- {
- var configfj = new BLL.T_Sys_SystemConfig().GetModelList(" F_ParamCode='FileUrlPath' ").FirstOrDefault();
- var model = new BLL.T_Sys_ApplicationsVersion().GetModelList("F_IsDelete=0 and F_Type=1 order by F_ID DESC ").FirstOrDefault();
- if (model != null)
- {
- ApplicationsVersion app = new ApplicationsVersion();
- app.F_ID = model.F_ID;
- app.F_Type = (int)model.F_Type;
- app.F_VersionName = model.F_VersionName;
- app.F_VersionCode = model.F_VersionCode;
- app.F_Files = model.F_Files;
- app.F_Url = model.F_Url;
- app.F_Sort = (int)model.F_Sort;
- app.F_Remarks = model.F_Remarks;
- app.FileUrl = GetFileData(model.F_Files, configfj.F_ParamValue);
- return Success("成功", app);
- }
- return Error("获取失败");
- }
- public ActionResult GetAndroid()
- {
- var configfj = new BLL.T_Sys_SystemConfig().GetModelList(" F_ParamCode='FileUrlPath' ").FirstOrDefault();
- var model = new BLL.T_Sys_ApplicationsVersion().GetModelList("F_IsDelete=0 and F_Type=0 order by F_ID DESC ").FirstOrDefault();
- if (model != null)
- {
- ApplicationsVersion app = new ApplicationsVersion();
- app.F_ID = model.F_ID;
- app.F_Type = (int)model.F_Type;
- app.F_VersionName = model.F_VersionName;
- app.F_VersionCode = model.F_VersionCode;
- app.F_Files = model.F_Files;
- app.F_Url = model.F_Url;
- app.F_Sort = (int)model.F_Sort;
- app.F_Remarks = model.F_Remarks;
- app.FileUrl = GetFileData(model.F_Files, configfj.F_ParamValue);
- return Success("成功", app);
- }
- return Error("获取失败");
- }
- /// <summary>
- /// 列表
- /// </summary>
- /// <returns></returns>
- public ActionResult GetList(string keywords, int pageindex = 1, int pagesize = 10)
- {
- DataTable dt = new DataTable();
- string sql = "and F_IsDelete=0";
- if (!string.IsNullOrWhiteSpace(keywords))//关键字搜索
- sql += $" and ( F_VersionName like '%" + keywords.Trim() + "%'or F_Type like '%" + keywords.Trim() + "%'or F_VersionCode like '%" + keywords.Trim() + "%' ) ";
- int recordCount = 0;
- if (!string.IsNullOrWhiteSpace(sql))
- {
- dt = BLL.PagerBLL.GetListPager(
- "T_Sys_ApplicationsVersion",
- "F_ID",
- "*",
- sql,
- "ORDER BY T_Sys_ApplicationsVersion.F_ID desc,F_Sort asc",
- pagesize,
- pageindex,
- true,
- out recordCount);
- }
-
- List<Model.T_Sys_ApplicationsVersion> modlelist = new BLL.T_Sys_ApplicationsVersion().DataTableToList(dt);
- if (modlelist.Count > 0)
- {
- var obj = new
- {
- state = "success",
- message = "成功",
- rows = modeltoip(modlelist),
- total = recordCount
- };
- return Content(obj.ToJson()); ;
- }
- else
- {
- return Success("暂无数据"); ;
- }
- }
- public DataTable GetFileData(string ids, string prefix)
- {
- DataTable dt = new DataTable();
- if (!string.IsNullOrEmpty(ids))
- {
- dt = DbHelperSQL.Query("select * from T_Sys_Accessories where F_Id in (" + ids + ")").Tables[0];
- foreach (DataRow dr in dt.Rows)
- {
- dr["F_Url"] = prefix + dr["F_Url"].ToString();
- }
- }
- return dt;
- }
- private List <ApplicationsVersion> modeltoip(List<Model.T_Sys_ApplicationsVersion >t_Sys_ApplicationsVersion )
- {
- var configfj = new BLL.T_Sys_SystemConfig().GetModelList(" F_ParamCode='FileUrlPath' ").FirstOrDefault();
- List<ApplicationsVersion> model = new List<ApplicationsVersion>();
- if (t_Sys_ApplicationsVersion!=null )
- {
- foreach (var it in t_Sys_ApplicationsVersion)
- {
- ApplicationsVersion app = new ApplicationsVersion();
- app.F_ID = it.F_ID;
- app.F_Type =(int ) it.F_Type;
- app.F_VersionName = it.F_VersionName;
- app.F_VersionCode = it.F_VersionCode;
- app.F_Files = it.F_Files;
- app.F_Url = it.F_Url;
- app.F_Sort = (int )it.F_Sort;
- app.F_Remarks = it.F_Remarks;
- app.FileUrl = GetFileData(it.F_Files, configfj.F_ParamValue);
- model.Add(app);
- }
- }
- return model;
- }
- /// <summary>
- /// 查询详情
- /// </summary>
- public ActionResult GetDetails(int id)
- {
- int userId = CurrentUser.UserData.F_UserId;
- if (userId != 0)
- {
- DataTable FileUrl = new DataTable();
- Model.T_Sys_UserAccount ua = new BLL.T_Sys_UserAccount().GetModel(userId);
- if (id <= 0)
- {
- return Error("请输入正确的id");
- }
- var model = ApplicationsBLL.GetModel(id);
- if (model == null)
- return Error("该应用不存在");
- List<Model.T_Sys_ApplicationsVersion> modlelist = new List<Model.T_Sys_ApplicationsVersion>();
- modlelist.Add(model);
- var obj = new
- {
- state = "success",
- message = "成功",
- rows = modeltoip(modlelist),
- };
- return Content(obj.ToJson());
- }
- else
- {
- return Error("无操作权限!");
- }
- }
- private BLL.T_Sys_UserAccount userBLL = new BLL.T_Sys_UserAccount();
- /// <summary>
- /// 上传附件
- /// </summary>
- /// <returns></returns>
- public ActionResult UploadFile()
- {
- int userId = CurrentUser.UserData.F_UserId;
- Model.T_Sys_UserAccount userModel = userBLL.GetModel(userId);
- #region 多个上传
- HttpFileCollection files = RequestString.GetFiles();
- if (files.Count > 0)
- {
- List<Model.T_Sys_Accessories> acs = new List<Model.T_Sys_Accessories>();
- string path = "/Upload/Files/" + DateTime.Now.ToString("yyyy") + "/" + DateTime.Now.ToString("MM") + "/" + DateTime.Now.ToString("dd") + "/";
- for (int i = 0; i < files.Count; i++)
- {
- HttpPostedFile file = files[i];
- FileUp fu = new FileUp();
- string name = fu.Upload(file, path);
- Model.T_Sys_Accessories model_T_Sys_Accessories = new Model.T_Sys_Accessories();
- model_T_Sys_Accessories.F_CreateTime = DateTime.Now;//上传时间
- model_T_Sys_Accessories.F_Name = file.FileName;//附件名称
- model_T_Sys_Accessories.F_Type = System.IO.Path.GetExtension(file.FileName);//附件类型
- model_T_Sys_Accessories.F_Url = path + name;//附件地址
- model_T_Sys_Accessories.F_Size = file.ContentLength;
- model_T_Sys_Accessories.F_CreateUser = userModel.F_UserCode;//上传人
- int id = new BLL.T_Sys_Accessories().Add(model_T_Sys_Accessories);
- model_T_Sys_Accessories.F_Id = id;
- acs.Add(model_T_Sys_Accessories);
- }
- return Success("成功", acs);
- }
- else
- {
- return Error("请选择要上传的文件");
- }
- #endregion
- }
- }
- }
|