using Learun.Application.Base.SystemModule; using Learun.Application.WorkFlow; using Learun.Util; using System; using System.Collections.Generic; using System.Web.Mvc; using System.Linq; using Learun.Util.Constant; namespace Learun.Application.Web.Areas.LR_NewWorkFlow.Controllers { /// /// 版 本 PIT-ADMS V7.0.3 敏捷开发框架 /// Copyright (c) 2013-2018 Hexagon PPM /// 创建人:研发部 /// 日 期:2018.12.06 /// 描 述:工作流模板(新) /// public class NWFSchemeController : MvcControllerBase { private NWFSchemeIBLL nWFSchemeIBLL = new NWFSchemeBLL(); private AnnexesFileIBLL annexesFileIBLL = new AnnexesFileBLL(); #region 视图功能 /// /// 主页面(协同设计平台) /// /// [HttpGet] public ActionResult Index() { return View(); } /// /// 主页面(系统管理) /// /// [HttpGet] public ActionResult CommonIndex() { return View(); } /// /// 表单页面(协同设计平台) /// /// [HttpGet] public ActionResult Form() { return View(); } /// /// 表单页面(系统管理) /// /// [HttpGet] public ActionResult CommonForm() { return View(); } /// /// 复制流程页面 /// /// [HttpGet] public ActionResult CopyForm() { return View(); } /// /// 表单页面 /// /// [HttpGet] public ActionResult ReIndex() { return View(); } /// /// 流程模板分类页面(单位) /// /// public ActionResult CategoryIndex() { return View(); } /// /// 流程模板分类表单(单位) /// /// public ActionResult CategoryForm() { return View(); } /// /// 流程模板分类页面(项目级) /// /// public ActionResult ReCategoryIndex() { return View(); } /// /// 流程模板分类表单(项目级) /// /// public ActionResult ReCategoryForm() { return View(); } /// /// 流程模板设计历史记录 /// /// [HttpGet] public ActionResult HistoryForm() { return View(); } /// /// 预览流程模板 /// /// [HttpGet] public ActionResult PreviewForm() { return View(); } /// /// 节点信息设置 /// /// [HttpGet] public ActionResult NodeForm() { return View(); } #region 审核人员添加 /// /// 添加岗位 /// /// [HttpGet] public ActionResult PostForm() { return View(); } /// /// 添加角色 /// /// [HttpGet] public ActionResult RoleForm() { return View(); } /// /// 添加用户 /// /// [HttpGet] public ActionResult UserForm() { return View(); } /// /// 添加上下级 /// /// [HttpGet] public ActionResult LevelForm() { return View(); } /// /// 添加某节点执行人 /// /// [HttpGet] public ActionResult AuditorNodeForm() { return View(); } /// /// 添加表单字段 /// /// [HttpGet] public ActionResult AuditorFieldForm() { return View(); } #endregion #region 表单添加 /// /// 表单添加 /// /// [HttpGet] public ActionResult WorkformForm() { return View(); } #endregion #region 条件字段 /// /// 条件字段添加 /// /// [HttpGet] public ActionResult ConditionFieldForm() { return View(); } #endregion #region 按钮设置 /// /// 表单添加 /// /// [HttpGet] public ActionResult ButtonForm() { return View(); } #endregion /// /// 线段信息设置 /// /// [HttpGet] public ActionResult LineForm() { return View(); } /// /// 导入页面 /// /// [HttpGet] public ActionResult ImportForm() { return View(); } #endregion #region 获取数据 /// /// 获取分页数据 /// /// 分页参数 /// 查询条件 /// [HttpGet] [AjaxOnly] public ActionResult GetInfoPageList(string pagination, string queryJson) { try { Pagination paginationobj = pagination.ToObject(); var data = nWFSchemeIBLL.GetInfoPageList(paginationobj, queryJson); var jsonData = new { rows = data, total = paginationobj.total, page = paginationobj.page, records = paginationobj.records, }; return Success(jsonData); } catch (Exception ex) { return Fail(ex.Message); } } /// /// 获取流程分类树形数据 /// /// 项目ID /// [HttpGet] [AjaxOnly] public ActionResult GetCategoryTree(string ProjectId, string Type) { string PlantType = string.Empty; if (Type == "create") { if (!ProjectId.IsEmpty()) { PlantType = Util.Constant.ConstantBiz.PLANTTYPE_PROJECT; } else { PlantType = Util.Constant.ConstantBiz.PLANTTYPE_UNIT; } } if (Request["plantType"] == Util.Constant.ConstantBiz.PLANTTYPE_UNIT) { PlantType = Util.Constant.ConstantBiz.PLANTTYPE_UNIT; } else if (Request["plantType"] == Util.Constant.ConstantBiz.PLANTTYPE_PROJECT) { PlantType = Util.Constant.ConstantBiz.PLANTTYPE_PROJECT; } var data = nWFSchemeIBLL.GetCategoryTree(ProjectId, PlantType); return Success(data); } /// /// 获取流程分类数据 /// /// /// [HttpGet] [AjaxOnly] public ActionResult GetCategoryList(string queryJson) { var data = nWFSchemeIBLL.GetCategoryList(queryJson); return Success(data); } /// /// 获取流程分类实体 /// /// 主键 /// [HttpGet] [AjaxOnly] public ActionResult GetCategoryForm(string keyValue) { var data = nWFSchemeIBLL.GetCategoryForm(keyValue); var jsonData = new { flow_category = data, }; return Success(jsonData); } /// /// 获取自定义流程列表 /// /// [HttpGet] [AjaxOnly] public ActionResult GetMyInfoList(string ProjectId, string keyword) { UserInfo userInfo = LoginUserInfo.Get(); var data = (List)nWFSchemeIBLL.GetInfoList(userInfo, ProjectId); if (!string.IsNullOrEmpty(keyword)) { data = data.FindAll(t => t.F_Name.Contains(keyword)); } return Success(data); } /// /// 获取流程模板数据 /// /// 主键 /// [HttpGet] [AjaxOnly] public ActionResult GetFormData(string keyValue) { NWFSchemeInfoEntity schemeInfoEntity = nWFSchemeIBLL.GetInfoEntity(keyValue); if (schemeInfoEntity == null) { return Success(new { }); } NWFSchemeEntity schemeEntity = nWFSchemeIBLL.GetSchemeEntity(schemeInfoEntity.F_SchemeId); var nWFSchemeAuthList = nWFSchemeIBLL.GetAuthList(schemeInfoEntity.F_Id); var jsonData = new { info = schemeInfoEntity, scheme = schemeEntity, authList = nWFSchemeAuthList }; return Success(jsonData); } /// /// 获取模板分页数据 /// /// 分页参数 /// /// [HttpGet] [AjaxOnly] public ActionResult GetSchemePageList(string pagination, string schemeInfoId) { Pagination paginationobj = pagination.ToObject(); var data = nWFSchemeIBLL.GetSchemePageList(paginationobj, schemeInfoId); var jsonData = new { rows = data, total = paginationobj.total, page = paginationobj.page, records = paginationobj.records, }; return Success(jsonData); } /// /// 获取流程模板数据 /// /// 模板主键 /// [HttpGet] [AjaxOnly] public ActionResult GetScheme(string schemeId) { var data = nWFSchemeIBLL.GetSchemeEntity(schemeId); return Success(data); } /// /// 获取流程模板数据 /// /// 流程编码 /// [HttpPost, ValidateInput(false)] public void ExportScheme(string code) { NWFSchemeInfoEntity schemeInfoEntity = nWFSchemeIBLL.GetInfoEntityByCode(code); if (schemeInfoEntity != null) { NWFSchemeEntity schemeEntity = nWFSchemeIBLL.GetSchemeEntity(schemeInfoEntity.F_SchemeId); var nWFSchemeAuthList = nWFSchemeIBLL.GetAuthList(schemeInfoEntity.F_Id); var jsonData = new { info = schemeInfoEntity, scheme = schemeEntity, authList = nWFSchemeAuthList }; string data = jsonData.ToJson(); FileDownHelper.DownLoadString(data, schemeInfoEntity.F_Name + ".lrscheme"); } } /// /// excel文件导入(通用模板) /// /// 模板Id /// 文件主键 /// 分片数 /// 文件扩展名 /// [HttpPost] [ValidateAntiForgeryToken] public ActionResult ExecuteImportScheme(string templateId, string fileId, int chunks, string ext) { UserInfo userInfo = LoginUserInfo.Get(); string path = annexesFileIBLL.SaveAnnexes(fileId, fileId + "." + ext, chunks, userInfo); if (!string.IsNullOrEmpty(path)) { // 读取导入文件 string data = DirFileHelper.ReadText(path); // 删除临时文件 DirFileHelper.DeleteFile2(path); string commonKeyValue = ""; if (!string.IsNullOrEmpty(data)) { NWFSchemeModel nWFSchemeModel = data.ToObject(); // 验证流程编码是否重复 var schemeInfoEntityTmpList = (List)nWFSchemeIBLL.GetInfoList(); if (schemeInfoEntityTmpList.Count > 0) { NWFSchemeInfoEntity schemeInfoEntityTmp = schemeInfoEntityTmpList.Find(s => s.F_Code == Str.ConvertPinYin(nWFSchemeModel.info.F_Name).ToUpper() && s.ProjectId == null); if (schemeInfoEntityTmp != null) { commonKeyValue = schemeInfoEntityTmp.F_Id; } } nWFSchemeModel.info.ProjectId = null; nWFSchemeIBLL.SaveEntity(commonKeyValue, nWFSchemeModel.info, nWFSchemeModel.scheme, nWFSchemeModel.authList); } return Success("导入成功"); } else { return Fail("导入模板失败!"); } } /// /// excel文件导入(项目平台) /// /// 模板Id /// 文件主键 /// 分片数 /// 文件扩展名 /// [HttpPost] [ValidateAntiForgeryToken] public ActionResult ImportScheme(string templateId, string fileId, int chunks, string ext, string ProjectId) { UserInfo userInfo = LoginUserInfo.Get(); string path = annexesFileIBLL.SaveAnnexes(fileId, fileId + "." + ext, chunks, userInfo); if (!string.IsNullOrEmpty(path)) { // 读取导入文件 string data = DirFileHelper.ReadText(path); // 删除临时文件 DirFileHelper.DeleteFile2(path); string keyValue = ""; if (!string.IsNullOrEmpty(data)) { NWFSchemeModel nWFSchemeModel = data.ToObject(); // 验证流程编码是否重复 var schemeInfoEntityTmpList = (List)nWFSchemeIBLL.GetInfoList(); if (schemeInfoEntityTmpList.Count > 0) { NWFSchemeInfoEntity schemeInfoEntityTmp = schemeInfoEntityTmpList.Find(s => s.F_Code == Str.ConvertPinYin(nWFSchemeModel.info.F_Name).ToUpper() && s.ProjectId == ProjectId); if (schemeInfoEntityTmp != null) { keyValue = schemeInfoEntityTmp.F_Id; } } nWFSchemeModel.info.ProjectId = ProjectId; nWFSchemeIBLL.SaveEntity(keyValue, nWFSchemeModel.info, nWFSchemeModel.scheme, nWFSchemeModel.authList); } return Success("导入成功"); } else { return Fail("导入模板失败!"); } } /// /// 获取流程模板列表 /// /// 流程分类 /// [HttpGet] [AjaxOnly] public ActionResult GetNWFSchemeInfoList(string category) { var schemeInfoLsit = (List)nWFSchemeIBLL.GetInfoList(); var data = schemeInfoLsit.FindAll(s => s.F_Category == category && string.IsNullOrEmpty(s.ProjectId)); return Success(data); } #endregion #region 提交数据 /// /// 保存流程模板 通用 /// /// 主键 /// 表单设计模板信息 /// 模板权限信息 /// 模板内容 /// 类型1.正式2.草稿 /// [HttpPost] [ValidateAntiForgeryToken] [AjaxOnly] public ActionResult CommonSaveForm(string keyValue, string schemeInfo, string shcemeAuth, string scheme, int type) { NWFSchemeInfoEntity schemeInfoEntity = schemeInfo.ToObject(); List nWFSchemeAuthList = shcemeAuth.ToObject>(); NWFSchemeEntity schemeEntity = new NWFSchemeEntity(); schemeEntity.F_Content = scheme; schemeEntity.F_Type = type; schemeInfoEntity.F_Code = Guid.NewGuid().ToString(); // 验证流程编码是否重复 var schemeInfoEntityTmpList = (List)nWFSchemeIBLL.GetInfoList(); if (schemeInfoEntityTmpList.Count > 0 && string.IsNullOrEmpty(keyValue)) { NWFSchemeInfoEntity schemeInfoEntityTmp = schemeInfoEntityTmpList.Find(s => s.F_Code == Str.ConvertPinYin(schemeInfoEntity.F_Name).ToUpper() && s.ProjectId == null); if (schemeInfoEntityTmp != null) { return Fail("流程名称重复"); } } nWFSchemeIBLL.SaveEntity(keyValue, schemeInfoEntity, schemeEntity, nWFSchemeAuthList); return Success("保存成功!"); } /// /// 保存流程模板 /// /// 主键 /// 表单设计模板信息 /// 模板权限信息 /// 模板内容 /// 类型1.正式2.草稿 /// [HttpPost] [ValidateAntiForgeryToken] [AjaxOnly] public ActionResult SaveForm(string keyValue, string schemeInfo, string shcemeAuth, string scheme, int type) { NWFSchemeInfoEntity schemeInfoEntity = schemeInfo.ToObject(); List nWFSchemeAuthList = shcemeAuth.ToObject>(); NWFSchemeEntity schemeEntity = new NWFSchemeEntity(); schemeEntity.F_Content = scheme; schemeEntity.F_Type = type; if (schemeInfoEntity.ProjectId == null) { return Fail("获取项目ID失败!"); } if (!string.IsNullOrEmpty(keyValue)) { schemeInfoEntity.ProjectId = null; } nWFSchemeIBLL.SaveEntity(keyValue, schemeInfoEntity, schemeEntity, nWFSchemeAuthList); return Success("保存成功!"); } /// /// 保存流程分类 /// /// 主键 /// 流程分类实体 [HttpPost] [ValidateAntiForgeryToken] [AjaxOnly] public ActionResult CategorySaveEntity(string keyValue, string strEntity) { try { NWFSchemeCategoryEntity entity = strEntity.ToObject(); if (string.IsNullOrEmpty(keyValue)) { if (entity.ProjectId == null) { return Fail("获取项目ID失败!"); } UserInfo us = LoginUserInfo.Get(); if (us == null) { return Fail("读取用户信息异常"); } entity.CreateUserID = us.userId; entity.CreateTime = Time.MySqlTime; } else { entity.ProjectId = null; } nWFSchemeIBLL.CategorySaveEntity(keyValue, entity); return Success("保存成功!"); } catch (Exception ex) { return Fail(ex.Message); } } /// /// 删除流程分类 /// /// 主键 /// 流程分类实体 [HttpPost] [AjaxOnly] public ActionResult CategoryDeleteEntity(string keyValue) { nWFSchemeIBLL.CategoryDeleteEntity(keyValue); return Success("删除成功!"); } /// /// 更新模板数据 /// /// 主键 /// [HttpPost] [AjaxOnly] public ActionResult UpdateForm(string keyValue) { var schemeInfoEntityTmpList = (List)nWFSchemeIBLL.GetInfoList(); // 当前模板数据 var currentSchemeInfo = schemeInfoEntityTmpList.Find(s => s.F_Id == keyValue); // 通用模板数据 var commonSchemeInfo = schemeInfoEntityTmpList.Find(s => s.F_Code == currentSchemeInfo.F_Code && string.IsNullOrEmpty(s.ProjectId) == true); if (commonSchemeInfo != null) { if (currentSchemeInfo != null) { var commonSchemeList = (List)nWFSchemeIBLL.GetNewSchemeEntityBySchemeInfoId(commonSchemeInfo.F_Id); if (commonSchemeList != null && commonSchemeList.Count > 0) { NWFSchemeEntity newCommonSchemeInfo = commonSchemeList.OrderByDescending(o => o.F_CreateDate).FirstOrDefault(); nWFSchemeIBLL.SaveEntity(currentSchemeInfo, newCommonSchemeInfo); } else { return Fail("更新失败,未找到通用模板!"); } } return Success("更新成功!"); } else { return Fail("更新失败,未找到通用模板!"); } } /// /// 删除模板数据 /// /// 主键 /// [HttpPost] [AjaxOnly] public ActionResult DeleteForm(string keyValue) { nWFSchemeIBLL.DeleteEntity(keyValue); return Success("删除成功!"); } /// /// 启用/停用表单 /// /// 主键 /// 状态1启用0禁用 /// [HttpPost] [AjaxOnly] public ActionResult UpDateSate(string keyValue, int state) { nWFSchemeIBLL.UpdateState(keyValue, state); return Success((state == 1 ? "启用" : "禁用") + "成功!"); } /// /// 更新表单模板版本 /// /// 主键 /// 状态1启用0禁用 /// [HttpPost] [AjaxOnly] public ActionResult UpdateScheme(string schemeInfoId, string schemeId) { nWFSchemeIBLL.UpdateScheme(schemeInfoId, schemeId); return Success("更新成功!"); } [HttpPost] [AjaxOnly] public ActionResult CopyScheme(string ProjectId) { if (!string.IsNullOrEmpty(ProjectId)) { //复制流程 nWFSchemeIBLL.CopyScheme(ProjectId); } return Success("保存成功!"); } #endregion } }