/// <summary> /// 保存微信菜单信息 /// </summary> /// <param name="dto"></param> /// <returns></returns> public ReturnMsg SaveWxMenuInfo(WctMenuMstrDto dto) { var rm = new ReturnMsg(); var entity = new WctMenuMstr(); var isOk = CheckWxMenuInfo(dto, rm); if (!isOk.IsSuccess) { return(rm); } if (string.IsNullOrEmpty(dto.Id)) { dto.Id = Guid.NewGuid().ToString("N"); dto.MENU_KEY = Guid.NewGuid().ToString("N"); dto.MENU_ID_NO = AbpSession.ORG_NO; _initHelper.InitAdd(dto, AbpSession.USR_ID, AbpSession.ORG_NO, AbpSession.BG_NO); entity = dto.ToEntity(); _wctMenuMstrRepository.Insert(entity); } else { _initHelper.InitUpdate(dto, AbpSession.USR_ID); entity = dto.ToEntity(); _wctMenuMstrRepository.Update(entity); } rm.IsSuccess = true; return(rm); }
public ActionResult SaveWxMenuInfo([FromBody] WctMenuMstrDto dto) { try { var result = _wctMenuMstrService.SaveWxMenuInfo(dto); if (!result.IsSuccess) { return(Fail(result.msg)); } return(Success("保存成功")); } catch (Exception ex) { return(Fail(ex.Message)); } }
/// <summary> /// 校验微信菜单信息 /// </summary> /// <param name="dto"></param> /// <param name="rm"></param> /// <returns></returns> public ReturnMsg CheckWxMenuInfo(WctMenuMstrDto dto, ReturnMsg rm) { if (string.IsNullOrEmpty(dto.MENU_NAME)) { rm.IsSuccess = false; rm.msg = "请输入菜单名称"; return(rm); } if (dto.MENU_ISSECOND == null) { rm.IsSuccess = false; rm.msg = "请选择是否支持二级菜单"; return(rm); } var nameByte = Encoding.Default.GetBytes(dto.MENU_NAME).Length; if (dto.MENU_LEVEL == 1 && nameByte > 12) { rm.IsSuccess = false; rm.msg = "一级菜单不能超过12个字节"; return(rm); } if (dto.MENU_LEVEL == 2 && nameByte > 16) { rm.IsSuccess = false; rm.msg = "二级菜单不能超过24个字节"; return(rm); } if (dto.MENU_DISPLAYINDEX == 0) { rm.IsSuccess = false; rm.msg = "请选择菜单序号"; return(rm); } if (dto.MENU_BELINKEDTYPE == null || dto.MENU_BELINKEDTYPE == 0) { rm.IsSuccess = false; rm.msg = "请选择菜单关联项"; return(rm); } if (dto.MENU_BELINKEDTYPE == 1 && string.IsNullOrEmpty(dto.MENU_MENUURL)) { rm.IsSuccess = false; rm.msg = "请填写链接地址"; return(rm); } if (dto.MENU_BELINKEDTYPE == 2) { if (dto.MENU_MATERIALTYPEID == null) { rm.IsSuccess = false; rm.msg = "请选择回复消息类型"; return(rm); } if (dto.MENU_MATERIALTYPEID == 0) { if (string.IsNullOrEmpty(dto.MENU_TEXT)) { rm.IsSuccess = false; rm.msg = "请填写文本内容"; return(rm); } } else { if (string.IsNullOrEmpty(dto.MATERIAL_IDS)) { rm.IsSuccess = false; rm.msg = "请选择图文素材"; return(rm); } var list = dto.MATERIAL_IDS.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries).ToList(); if (list.Count > 8) { rm.IsSuccess = false; rm.msg = "图文素材不可超过8个"; return(rm); } } } if (dto.MENU_BELINKEDTYPE == 3) { if (string.IsNullOrEmpty(dto.MENU_MODULEID)) { rm.IsSuccess = false; rm.msg = "请选择关联系统模块"; return(rm); } if (string.IsNullOrEmpty(dto.MENU_MENUURL)) { rm.IsSuccess = false; rm.msg = "系统模块地址不可为空"; return(rm); } } if (dto.MENU_BELINKEDTYPE == 4) { if (string.IsNullOrEmpty(dto.MENU_APPLET_ID)) { rm.IsSuccess = false; rm.msg = "请选择关联小程序"; return(rm); } if (string.IsNullOrEmpty(dto.MENU_APPLET_APP_ID)) { rm.IsSuccess = false; rm.msg = "关联小程序appId不可为空"; return(rm); } if (string.IsNullOrEmpty(dto.MENU_MENUURL)) { rm.IsSuccess = false; rm.msg = "小程序地址不可为空"; return(rm); } } if (string.IsNullOrEmpty(dto.MENU_TYPE)) { rm.IsSuccess = false; rm.msg = "菜单类型有误"; return(rm); } if (dto.MENU_LEVEL == 0) { rm.IsSuccess = false; rm.msg = "菜单层级有误"; return(rm); } if (dto.MENU_LEVEL == 2 && string.IsNullOrEmpty(dto.MENU_PARENTID)) { rm.IsSuccess = false; rm.msg = "父级菜单不可为空"; return(rm); } var result = new List <WctMenuMstr>(); result = GetExpressionResult(dto.Id, c => c.MENU_NAME == dto.MENU_NAME && c.MENU_LEVEL == dto.MENU_LEVEL && c.DEL_FLAG == 1 && c.MENU_STATUS == 1); if (result.Count > 0) { rm.IsSuccess = false; rm.msg = "该菜单名称已存在"; return(rm); } if (string.IsNullOrEmpty(dto.MENU_PARENTID)) { result = GetExpressionResult(dto.Id, c => c.MENU_DISPLAYINDEX == dto.MENU_DISPLAYINDEX && c.MENU_LEVEL == dto.MENU_LEVEL && c.DEL_FLAG == 1 && c.MENU_STATUS == 1); } else { result = GetExpressionResult(dto.Id, c => c.MENU_PARENTID == dto.MENU_PARENTID && c.MENU_DISPLAYINDEX == dto.MENU_DISPLAYINDEX && c.MENU_LEVEL == dto.MENU_LEVEL && c.DEL_FLAG == 1 && c.MENU_STATUS == 1); } if (result.Count > 0) { rm.IsSuccess = false; rm.msg = "该序号已存在"; return(rm); } if (dto.MENU_LEVEL == 1) { result = GetExpressionResult(dto.Id, c => c.MENU_LEVEL == dto.MENU_LEVEL && c.DEL_FLAG == 1 && c.MENU_STATUS == 1); if (dto.MENU_LEVEL == 1 && result.Count >= 3) { rm.IsSuccess = false; rm.msg = "一级菜单最多创建3个"; return(rm); } } else { result = GetExpressionResult(dto.Id, c => c.MENU_PARENTID == dto.MENU_PARENTID && c.MENU_LEVEL == dto.MENU_LEVEL && c.DEL_FLAG == 1 && c.MENU_STATUS == 1); if (dto.MENU_LEVEL == 2 && result.Count >= 5) { rm.IsSuccess = false; rm.msg = "二级菜单最多创建5个"; return(rm); } } rm.IsSuccess = true; return(rm); }