using Newtonsoft.Json.Linq; using System; using System.Collections.Generic; using System.Data; using System.Globalization; using System.IO; using System.Linq; using System.Net; using System.Net.Http; using System.Web; using System.Web.Http; using VueWebApi.DLL.BLL; using VueWebApi.Tools; namespace VueWebApi.Controllers { [RoutePrefix(prefix: "api/SystemSetting")] [ControllerGroup("系统设置", "在线接口")] [ChannelActionFilter] public class SystemSettingController : ApiController { //定义全局信息返回变量 ToMessage mes = new ToMessage(); RedisHelper redis = new RedisHelper(); string FileIP = System.Configuration.ConfigurationManager.AppSettings["FileIP"]; #region[编码规则查询] /// /// 编码规则查询 /// /// 编码名称 /// 固定字符 /// 页码 /// 每页显示条数 /// 排序字段 /// 排序规则 /// [Route(template: "EncodingRules")] [HttpGet] public HttpResponseMessage EncodingRules(string rightname = null, string prefix = null, int page = 0, int rows = 0, string prop = null, string order = null) { int startNum = rows * (page - 1) + 1; //起始记录rowNum int endNum = rows * page; //结束记录 rowNum mes = SystemSettingBLL.EncodingRules(rightname, prefix,startNum, endNum, prop, order); return TJson.toJson(mes); } #endregion #region[编码规则编辑保存] /// /// 编码规则编辑保存 /// /// 提交数据对象 /// [Route(template: "SaveEncodingRules")] [HttpPost] public HttpResponseMessage SaveEncodingRules([FromBody] JObject obj) { string rightcode = obj["rightcode"].ToString(); //功能编码 string rightname = obj["rightname"].ToString(); //功能名称 string prefix = obj["prefix"].ToString(); //固定字符 string filingdate = obj["filingdate"].ToString(); //提交日期 string incbit = obj["incbit"].ToString(); //自增位数 var lm_user = HttpContext.Current.Request.Cookies["admin"].Value.ToString(); //操作人员 mes = SystemSettingBLL.SaveEncodingRules(rightcode, rightname,prefix, filingdate, incbit, lm_user); return TJson.toJson(mes); } #endregion #region[获取规则生成的编码] /// /// 获取规则生成的编码 /// /// 功能编码 /// [Route(template: "NewEncodingRules")] [HttpGet] public HttpResponseMessage NewEncodingRules(string rightcode=null) { mes = SystemSettingBLL.NewEncodingRules(rightcode); return TJson.toJson(mes); } #endregion #region[车间公告列表] /// /// 车间公告列表 /// /// 车间编码 /// 公告主题 /// 公告内容 /// 是否撤销 /// 公告等级 /// 页码 /// 每页显示条数 /// 排序字段 /// 排序规则 /// [Route(template: "SystemAnnouncementSearch")] [HttpGet] public HttpResponseMessage SystemAnnouncementSearch(string wkspcode = null, string ancetitle = null,string ancecont=null,string cancel=null,string level=null, int page = 0, int rows = 0, string prop = null, string order = null) { int startNum = rows * (page - 1) + 1; //起始记录rowNum int endNum = rows * page; //结束记录 rowNum mes = SystemSettingBLL.SystemAnnouncementSearch(wkspcode, ancetitle, ancecont, cancel, level, startNum, endNum, prop, order); return TJson.toJson(mes); } #endregion #region[车间公告新增编辑提交] /// /// 车间公告新增编辑提交 /// /// id /// 车间集合 /// 公告主题 /// 公告内容 /// 公告等级 /// 是否撤销 /// 操作类型 /// [Route(template: "SystemAnnouncementAddUpdate")] [HttpPost] public HttpResponseMessage SystemAnnouncementAddUpdate(DataTable dt,string ancetitle,string ancecont,string level,string cancel,string opertype, string id = null) { var username = HttpContext.Current.Request.Cookies["admin"].Value.ToString(); //操作人员 mes = SystemSettingBLL.SystemAnnouncementAddUpdate(id,dt, ancetitle, ancecont, cancel, level, username, opertype); return TJson.toJson(mes); } #endregion #region[车间公告删除] /// /// 车间公告删除 /// /// id /// [Route(template: "SystemAnnouncementDelete")] [HttpPost] public HttpResponseMessage SystemAnnouncementDelete(string id) { mes = SystemSettingBLL.SystemAnnouncementDelete(id); return TJson.toJson(mes); } #endregion #region[SOP列表查询] /// /// SOP列表查询 /// /// 搜索关键字 /// 是否选中最高版本 /// 页码 /// 每页显示条数 /// 排序字段 /// 排序规则 /// [Route(template: "SystemSopSearch")] [HttpGet] public HttpResponseMessage SystemSopSearch(string search = null, string check = null,int page = 0, int rows = 0, string prop = null, string order = null) { int startNum = rows * (page - 1) + 1; //起始记录rowNum int endNum = rows * page; //结束记录 rowNum mes = SystemSettingBLL.SystemSopSearch(search, check, startNum, endNum, prop, order); return TJson.toJson(mes); } #endregion #region[SOP文件上传查找设备类型数据] /// /// SOP文件上传查找设备类型数据 /// /// [Route(template: "SystemSopDeviceSearch")] [HttpGet] public HttpResponseMessage SystemSopDeviceSearch() { mes = SystemSettingBLL.SystemSopDeviceSearch(); return TJson.toJson(mes); } #endregion #region[SOP文件作业文件上传获取最大版本号] /// /// SOP文件作业文件上传获取最大版本号 /// /// 设备类型编号 /// 文件类型编号 /// 物料编码 /// [Route(template: "SystemSopMaxVersion")] [HttpGet] public HttpResponseMessage SystemSopMaxVersion(string devicetypecode,string filetypecode,string partcode) { mes = SystemSettingBLL.SystemSopMaxVersion(devicetypecode, filetypecode, partcode); return TJson.toJson(mes); } #endregion #region[SOP文件上传提交] /// /// SOP文件上传提交 /// /// [Route(template: "SystemSopSava")] [HttpPost] public HttpResponseMessage SystemSopSava() { string savePath = ""; HttpPostedFile files = HttpContext.Current.Request.Files[0];//获取上传的文件 string devicetypecode = HttpContext.Current.Request["devicetypecode"].ToString();//设备类型编码 string partcode = HttpContext.Current.Request["partcode"].ToString();//物料编码 string filetypecode = HttpContext.Current.Request["filetypecode"].ToString();//文件类型编码 string fileversion = HttpContext.Current.Request["fileversion"].ToString();//文件版本号 string defilename = HttpContext.Current.Request["defilename"].ToString();//文件名称 var username = HttpContext.Current.Request.Cookies["admin"].Value.ToString(); //操作人员 if (files == null || files.ContentLength <= 0) { mes.code = "300"; mes.Message = "文件不能为空!"; } else { string file_name = DateTime.Now.ToString("yyyyMMddHHmmss", DateTimeFormatInfo.InvariantInfo) + Path.GetFileName(files.FileName); //时间戳加文件名 int filesize = files.ContentLength;//获取上传文件的大小单位为字节byte string fileEx = System.IO.Path.GetExtension(file_name);//获取上传文件的扩展名 int Maxsize = 40000 * 1024;//定义上传文件的最大空间大小为40M string FileType = ".pdf";//定义上传文件的类型字符串 string FileType1 = ".mp4";//定义上传文件的类型字符串 if (!FileType.Contains(fileEx) && !FileType1.Contains(fileEx)) { mes.code = "300"; mes.Message = "文件类型不对,只能导入pdf格式的文件和mp4格式文件!"; } else { if (filesize >= Maxsize) { mes.code = "300"; mes.Message = "上传文件超过40M,不能上传!"; } else { string path = System.Web.HttpContext.Current.Server.MapPath("/File/DeviceFile/"); if (Directory.Exists(path) == false)//如果不存在就创建file文件夹 { Directory.CreateDirectory(path); //添加文件夹 } savePath = Path.Combine(path, file_name); if (Directory.Exists(savePath) == true) //如果存在重名文件就提示 { mes.code = "300"; mes.Message = "已存在同名文件!"; } else { files.SaveAs(savePath); //将选择的文件保存到指定文件夹下 string FilesName = System.Web.HttpContext.Current.Server.MapPath("/File/DeviceFile/" + file_name); string StrPath = "/File/DeviceFile/" + file_name; mes = SystemSettingBLL.SystemSopSava(devicetypecode, filetypecode, partcode,fileversion,file_name,defilename,username, StrPath); } } } } return TJson.toJson(mes); } #endregion #region[SOP文件删除] /// /// SOP文件删除 /// /// 文件id /// 文件地址 /// [Route(template: "SystemSopDelete")] [HttpPost] public HttpResponseMessage SystemSopDelete(string id,string filepath) { mes = SystemSettingBLL.SystemSopDelete(id,filepath); return TJson.toJson(mes); } #endregion #region[SOP文件预览] /// /// SOP文件预览 /// /// 文件id /// 文件地址 /// [Route(template: "SystemSopView")] [HttpPost] public HttpResponseMessage SystemSopView(string id, string filepath) { mes.code = "200"; mes.data = Url.Content(FileIP + filepath); return TJson.toJson(mes); } #endregion } }