using System.Web; using System.Web.Http; using Model; using System.Collections.Generic; using System.IO; using System.Configuration; using System; namespace Mvc.Controllers { public class CommenInfoController : ApiController { // // GET: /CommenInfo/ [HttpGet] public ResponseData> GetSubUnitList(string projectId, string unitType = "", string name = "") { ResponseData> res = new ResponseData>(); if (string.IsNullOrEmpty(name)) name = ""; if (string.IsNullOrEmpty(unitType)) unitType = ""; List q = BLL.ProjectUnitService.GetProjectUnitListByProjectIdForApi(projectId, unitType, name); List a = new List(); for (int i = 0; i < q.Count; i++) { var unit = q[i].Base_Unit; unit.UnitTypeId = q[i].UnitType; a.Add(BeanUtil.CopyOjbect(unit, true)); } res.successful = true; res.resultValue = a; return res; } /// /// 根据项目Id和单位Id获取项目单位类型 /// /// /// /// [HttpGet] public ResponseData GetUnitType(string projectId, string unitId) { ResponseData res = new ResponseData(); string unitType = string.Empty; var projectUnit = BLL.ProjectUnitService.GetProjectUnitByUnitIdProjectId(projectId, unitId); if (projectUnit != null) { unitType = projectUnit.UnitType; } res.successful = true; res.resultValue = unitType; return res; } /// /// 获取质量问题类别 /// /// [HttpGet] public ResponseData> GetQualityQuestionType() { ResponseData> res = new ResponseData>(); List q = BLL.QualityQuestionTypeService.GetList(); List a = new List(); for (int i = 0; i < q.Count; i++) { a.Add(BeanUtil.CopyOjbect(q[i], true)); } res.successful = true; res.resultValue = a; return res; } public ResponseData> GetMainItemList(string projectId, string unitWorks = "", string name = "") { ResponseData> res = new ResponseData>(); if (string.IsNullOrEmpty(name)) name = ""; if (string.IsNullOrEmpty(unitWorks)) unitWorks = ""; res.resultValue = BLL.MainItemService.GetMainItemList(projectId, unitWorks, name); res.successful = true; return res; } [HttpGet] public ResponseData> GetUnitWorkListByPid(string projectId) { ResponseData> res = new ResponseData>(); List a = BLL.UnitWorkService.GetUnitWorkListByPid(projectId); List q = new List(); foreach (var u in a) { var temp = BeanUtil.CopyOjbect(u, true); temp.UnitWorkId = u.UnitWorkId; temp.UnitWorkName = u.UnitWorkCode + "-" + u.UnitWorkName + BLL.UnitWorkService.GetProjectType(u.ProjectType); q.Add(temp); } res.successful = true; res.resultValue = q; return res; } [HttpGet] public ResponseData> GetUnitWorkListByPidAndPtype(string projectId, string projectType) { ResponseData> res = new ResponseData>(); List a = BLL.UnitWorkService.GetUnitWorkListByPidForApi(projectId, projectType); List q = new List(); foreach (var u in a) { var temp = BeanUtil.CopyOjbect(u, true); temp.UnitWorkId = u.UnitWorkId; temp.UnitWorkName = u.UnitWorkCode + "-" + u.UnitWorkName + BLL.UnitWorkService.GetProjectType(u.ProjectType); q.Add(temp); } res.successful = true; res.resultValue = q; return res; } [HttpGet] public ResponseData> GetCNProfessionalMainItem() { ResponseData> res = new ResponseData>(); List resList = new List(); var list = BLL.CNProfessionalService.GetList(); if (list != null) { foreach (var item in list) { Base_CNProfessional main = new Base_CNProfessional(); main.CNProfessionalCode = item.CNProfessionalId; main.SortIndex = item.SortIndex; main.ProfessionalName = item.ProfessionalName; resList.Add(main); } } res.successful = true; res.resultValue = resList; return res; } [HttpGet] public ResponseData> GetDesignProfessionalMainItem() { ResponseData> res = new ResponseData>(); List resList = new List(); var list = BLL.DesignProfessionalService.GetList(); if (list != null) { foreach (var item in list) { Base_DesignProfessional main = new Base_DesignProfessional(); main.DesignProfessionalId = item.DesignProfessionalId; main.SortIndex = item.SortIndex; main.ProfessionalName = item.ProfessionalName; resList.Add(main); } } res.successful = true; res.resultValue = resList; return res; } [HttpGet] public ResponseData> FindAllUser() { ResponseData> res = new ResponseData>(); List list; list = BLL.UserService.GetUserList(); List users = new List(); foreach (var item in list) { users.Add(BeanUtil.CopyOjbect(item, true)); } res.successful = true; res.resultValue = users; return res; } [HttpGet] public ResponseData> FindAllUser(string projectId, string name = "") { ResponseData> res = new ResponseData>(); List list; if (string.IsNullOrEmpty(name)) name = ""; list = BLL.UserService.GetProjectUserListByProjectIdForApi(projectId, name); List users = new List(); foreach (var item in list) { users.Add(BeanUtil.CopyOjbect(item, true)); } res.successful = true; res.resultValue = users; return res; } [HttpGet] public ResponseData> FindUserByUnit(string projectId, string unitId = "", string unitType = "", string name = "") { ResponseData> res = new ResponseData>(); List list; if (string.IsNullOrEmpty(unitId)) unitId = ""; if (string.IsNullOrEmpty(unitType)) unitType = ""; if (string.IsNullOrEmpty(name)) name = ""; list = BLL.UserService.GetProjectUserListByProjectIdForApi(projectId, unitId, unitType, name); List users = new List(); foreach (var item in list) { users.Add(BeanUtil.CopyOjbect(item, true)); } res.successful = true; res.resultValue = users; return res; } [HttpGet] public ResponseData GetUserById(string userId) { ResponseData res = new ResponseData(); Model.Sys_User u = BLL.UserService.GetUserByUserId(userId); Model.Sys_User tempu = BeanUtil.CopyOjbect(u, true); if (u.Base_Unit != null) { tempu.UnitId = u.UnitId + u.Base_Unit.UnitName; } res.successful = true; res.resultValue = tempu; return res; } [HttpGet] public ResponseData> GetAllWorkPackage(string unitWorkId) { ResponseData> res = new ResponseData>(); List list = new List(); List pagelist = BLL.WorkPackageService.GetAllWorkPackagesByUnitWorkId(unitWorkId); foreach (WBS_WorkPackage w in pagelist) { WBS_WorkPackage temp = BeanUtil.CopyOjbect(w, true); temp.UnitWorkId = w.UnitWorkId; list.Add(temp); } res.resultValue = list; res.successful = true; return res; } [HttpGet] public ResponseData> GetControlItemAndCycle(string workPackageId) { ResponseData> res = new ResponseData>(); List list = new List(); List pagelist = BLL.ControlItemAndCycleService.GetListByWorkPackageIdForApi(workPackageId); ; foreach (WBS_ControlItemAndCycle w in pagelist) { var item = BeanUtil.CopyOjbect(w, true); item.CheckNum = w.CheckNum; list.Add(item); } res.resultValue = list; res.successful = true; return res; } [HttpGet] public ResponseData> FindAllUnit(string projectId = "") { ResponseData> res = new ResponseData>(); List list = BLL.UnitService.GetMainAndSubUnitByProjectIdList(projectId); List units = new List(); foreach (var item in list) { units.Add(BeanUtil.CopyOjbect(item, true)); } res.successful = true; res.resultValue = units; return res; } // // GET: /FileUpload/ /// /// 附件上传 /// /// public String FileUploadForWX() { HttpFileCollection files = HttpContext.Current.Request.Files; string typeName = HttpContext.Current.Request["typeName"]; if (string.IsNullOrEmpty(typeName)) { typeName = "WebApi"; } string reUrl = string.Empty; if (files != null && files.Count > 0) { string folderUrl = "FileUpLoad/" + typeName + "/" + DateTime.Now.ToString("yyyy-MM") + "/"; string localRoot = ConfigurationManager.AppSettings["localRoot"] + folderUrl; //物理路径 if (!Directory.Exists(localRoot)) { Directory.CreateDirectory(localRoot); } foreach (string key in files.AllKeys) { HttpPostedFile file = files[key];//file.ContentLength文件长度 if (!string.IsNullOrEmpty(file.FileName)) { string fileName = Guid.NewGuid() + Path.GetExtension(file.FileName); file.SaveAs(localRoot + fileName); if (string.IsNullOrEmpty(reUrl)) { reUrl += folderUrl + fileName; } else { reUrl += "," + folderUrl + fileName; } } } } return reUrl; } // // GET: /FileUpload/ /// /// 附件上传 /// /// public ResponseData FileUpload() { HttpFileCollection files = HttpContext.Current.Request.Files; string typeName = HttpContext.Current.Request["typeName"]; string fName = HttpContext.Current.Request["fileName"]; if (string.IsNullOrEmpty(typeName)) { typeName = "WebApi"; } string reUrl = string.Empty; if (files != null && files.Count > 0) { string folderUrl = "FileUpLoad/" + typeName + "/" + DateTime.Now.ToString("yyyy-MM") + "/"; string localRoot = ConfigurationManager.AppSettings["localRoot"] + folderUrl; //物理路径 if (!Directory.Exists(localRoot)) { Directory.CreateDirectory(localRoot); } foreach (string key in files.AllKeys) { HttpPostedFile file = files[key];//file.ContentLength文件长度 if (!string.IsNullOrEmpty(file.FileName)) { string fileName = Guid.NewGuid() + Path.GetExtension(file.FileName); if (!string.IsNullOrEmpty(fName)) fileName = Guid.NewGuid() + "_" + fName;// Path.GetExtension(file.FileName); file.SaveAs(localRoot + fileName); if (string.IsNullOrEmpty(reUrl)) { reUrl += folderUrl + fileName; } else { reUrl += "," + folderUrl + fileName; } } } } ResponseData res = new ResponseData(); res.successful = true; res.resultValue = reUrl; return res; //HttpFileCollection files = HttpContext.Current.Request.Files; //string typeName = HttpContext.Current.Request["typeName"]; //string fName = HttpContext.Current.Request["fileName"]; //if (string.IsNullOrEmpty(typeName)) //{ // typeName = "WebApi"; //} //string reUrl = string.Empty; //if (files != null && files.Count > 0) //{ // string folderUrl = "FileUpLoad/" + typeName + "/" + DateTime.Now.ToString("yyyy-MM") + "/"; // string localRoot = ConfigurationManager.AppSettings["localRoot"] + folderUrl; //物理路径 // if (!Directory.Exists(localRoot)) // { // Directory.CreateDirectory(localRoot); // } // foreach (string key in files.AllKeys) // { // HttpPostedFile file = files[key];//file.ContentLength文件长度 // if (!string.IsNullOrEmpty(file.FileName)) // { // string fileName = Guid.NewGuid() + Path.GetExtension(file.FileName); // file.SaveAs(localRoot + fileName); // if (string.IsNullOrEmpty(reUrl)) // { // reUrl += folderUrl + fileName; // } // else // { // reUrl += "," + folderUrl + fileName; // } // } // } //} //ResponseData res = new ResponseData(); //res.successful = true; //res.resultValue = reUrl; //return res; } [HttpGet] public ResponseData getDefaultCode(string projectId, string type) { ResponseData res = new ResponseData(); res.successful = true; switch (type) { case "checkList": { string prefix = BLL.ProjectService.GetProjectByProjectId(projectId).ProjectCode + "-06-CM03-XJ-"; res.resultValue = BLL.SQLHelper.RunProcNewId("SpGetNewCode5", "dbo.Check_CheckControl", "DocCode", prefix); } break; case "jointCheck": { string prefix = BLL.ProjectService.GetProjectByProjectId(projectId).ProjectCode + "-GJ-"; res.resultValue = BLL.SQLHelper.RunProcNewId("SpGetNewCode3", "dbo.Check_JointCheck", "JointCheckCode", prefix); } break; case "TechnicalContact": { res.resultValue = BLL.SQLHelper.RunProcNewId2("SpGetNewCode3ByProjectId", "dbo.Check_TechnicalContactList", "Code", projectId); } break; case "design": { res.resultValue = BLL.SQLHelper.RunProcNewId2("SpGetNewCode3ByProjectId", "dbo.Check_Design", "DesignCode", projectId); } break; case "contact": { res.resultValue = BLL.SQLHelper.RunProcNewId2("SpGetNewCode3ByProjectId", "dbo.Unqualified_WorkContact", "Code", projectId); } break; case "spotCheck": { string prefix = BLL.ProjectService.GetProjectByProjectId(projectId).ProjectCode + "-06-CM03-XJ-"; res.resultValue = BLL.SQLHelper.RunProcNewId("SpGetNewCode5", "dbo.Check_SpotCheck", "DocCode", prefix); } break; } return res; } } }