|
@ -57,7 +57,7 @@ public class WxMenuService extends BaseJpaService<WxMenu, WxMenuDao> {
|
|
|
}
|
|
|
String supMenucode = wxMenu.getSupMenucode();
|
|
|
if(StringUtils.isEmpty(supMenucode)) {//如果是空,则为父菜单
|
|
|
List<WxMenu> childMenus = findChildMenus(wxMenu.getWechatCode(), wxMenu.getSupMenucode());
|
|
|
List<WxMenu> childMenus = findChildMenus(wxMenu.getWechatCode(), wxMenu.getCode());
|
|
|
if(childMenus!=null){
|
|
|
for(WxMenu wxmenu:childMenus){
|
|
|
wxmenu.setStatus(-1);
|
|
@ -82,6 +82,15 @@ public class WxMenuService extends BaseJpaService<WxMenu, WxMenuDao> {
|
|
|
return wxMenuDao.findByWechatCode(wechatCode);
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 根据wechatCode查找所有菜单
|
|
|
* @param wechatCode
|
|
|
* @return
|
|
|
*/
|
|
|
public List<WxMenu> findParentMenuByWechatCode(String wechatCode){
|
|
|
return wxMenuDao.findParentMenuByWechatCode(wechatCode);
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 根据wechatCode在微信公众号创建菜单
|
|
|
* @param wechatCode
|
|
@ -145,8 +154,8 @@ public class WxMenuService extends BaseJpaService<WxMenu, WxMenuDao> {
|
|
|
if(!StringUtils.isEmpty(menu.getType())){
|
|
|
menuJsonStr += ",\"type\":\"" + menu.getType()+"\"";
|
|
|
}
|
|
|
if(!StringUtils.isEmpty(menu.getKey())){
|
|
|
menuJsonStr += ",\"key\":\"" + menu.getKey()+"\"";
|
|
|
if(!StringUtils.isEmpty(menu.getMenuKey())){
|
|
|
menuJsonStr += ",\"key\":\"" + menu.getMenuKey()+"\"";
|
|
|
}
|
|
|
if(!StringUtils.isEmpty(menu.getUrl())){
|
|
|
menuJsonStr += ",\"url\":\"" + menu.getUrl()+"\"";
|
|
@ -176,31 +185,85 @@ public class WxMenuService extends BaseJpaService<WxMenu, WxMenuDao> {
|
|
|
private boolean canSaveOrUpata(WxMenu wxMenu){
|
|
|
if (StringUtils.isEmpty(wxMenu.getCode())) {
|
|
|
throw new ApiException(WxContants.WxMenu.message_fail_code_is_null, CommonContants.common_error_params_code);
|
|
|
}//通过wechatCode查找是否有父菜单,若没有父菜单,则不让创建子菜单
|
|
|
}
|
|
|
String wechatCode = wxMenu.getWechatCode();
|
|
|
if (StringUtils.isEmpty(wechatCode)) {
|
|
|
throw new ApiException(WxContants.WxMenu.message_fail_wechatCode_is_null, CommonContants.common_error_params_code);
|
|
|
}
|
|
|
String name = wxMenu.getName();
|
|
|
if (StringUtils.isEmpty(name)) {
|
|
|
throw new ApiException(WxContants.WxMenu.message_fail_name_is_null, CommonContants.common_error_params_code);
|
|
|
}
|
|
|
String supMenucode = wxMenu.getSupMenucode();
|
|
|
if (!StringUtils.isEmpty(supMenucode)) {//不为空,说明是子菜单,判断父菜单是否存在
|
|
|
//说明是子菜单
|
|
|
List<WxMenu> childMenus = findChildMenus(wechatCode, supMenucode);
|
|
|
if(childMenus==null||childMenus.size()==0){
|
|
|
throw new ApiException(WxContants.WxMenu.message_fail_supMenuCode_is_no_exist, CommonContants.common_error_params_code);
|
|
|
}
|
|
|
if(childMenus.size()==5){
|
|
|
throw new ApiException(WxContants.WxMenu.message_fail_childMenu_is_to_much, CommonContants.common_error_params_code);
|
|
|
}
|
|
|
if(name.getBytes().length>60){
|
|
|
throw new ApiException(WxContants.WxMenu.message_fail_name_is_to_long, CommonContants.common_error_params_code);
|
|
|
}
|
|
|
if(StringUtils.isEmpty(wxMenu.getType())){
|
|
|
throw new ApiException(WxContants.WxMenu.message_fail_type_is_null, CommonContants.common_error_params_code);
|
|
|
}
|
|
|
}else{
|
|
|
//说明是父菜单
|
|
|
if(name.getBytes().length>16){
|
|
|
throw new ApiException(WxContants.WxMenu.message_fail_name_is_to_long, CommonContants.common_error_params_code);
|
|
|
}
|
|
|
//查找父菜单
|
|
|
List<WxMenu> parentMenus = findParentMenuByWechatCode(wechatCode);
|
|
|
if(parentMenus!=null){
|
|
|
if(parentMenus.size()==3){
|
|
|
throw new ApiException(WxContants.WxMenu.message_fail_parentMenu_is_to_much, CommonContants.common_error_params_code);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
}
|
|
|
if (StringUtils.isEmpty(wxMenu.getName())) {
|
|
|
throw new ApiException(WxContants.WxMenu.message_fail_name_is_null, CommonContants.common_error_params_code);
|
|
|
}
|
|
|
if(StringUtils.isEmpty(wxMenu.getType())){
|
|
|
throw new ApiException(WxContants.WxMenu.message_fail_type_is_null, CommonContants.common_error_params_code);
|
|
|
String type1=wxMenu.getType();
|
|
|
if(type1==null){
|
|
|
type1="";
|
|
|
}
|
|
|
if("click".equals(wxMenu.getType().toUpperCase())){
|
|
|
String key = wxMenu.getKey();
|
|
|
String type = type1.toUpperCase();
|
|
|
if("click".equals(type)){
|
|
|
String key = wxMenu.getMenuKey();
|
|
|
if(StringUtils.isEmpty(key)){
|
|
|
throw new ApiException(WxContants.WxMenu.message_fail_wxMenuKey_is_null, CommonContants.common_error_params_code);
|
|
|
throw new ApiException(WxContants.WxMenu.message_fail_key_is_null, CommonContants.common_error_params_code);
|
|
|
}
|
|
|
if(key.getBytes().length>128){
|
|
|
throw new ApiException(WxContants.WxMenu.message_fail_wxMenuKey_is_toLong, CommonContants.common_error_params_code);
|
|
|
throw new ApiException(WxContants.WxMenu.message_fail_key_is_toLong, CommonContants.common_error_params_code);
|
|
|
}
|
|
|
}
|
|
|
String url = wxMenu.getUrl();
|
|
|
if("view".equals(type)){
|
|
|
if(StringUtils.isEmpty(url)){
|
|
|
throw new ApiException(WxContants.WxMenu.message_fail_url_is_null, CommonContants.common_error_params_code);
|
|
|
}
|
|
|
if(url.getBytes().length>128){
|
|
|
throw new ApiException(WxContants.WxMenu.message_fail_url_is_toLong, CommonContants.common_error_params_code);
|
|
|
}
|
|
|
}
|
|
|
if("miniprogram".equals(type)){
|
|
|
if(StringUtils.isEmpty(url)){
|
|
|
throw new ApiException(WxContants.WxMenu.message_fail_url_is_null, CommonContants.common_error_params_code);
|
|
|
}
|
|
|
if(url.getBytes().length>128){
|
|
|
throw new ApiException(WxContants.WxMenu.message_fail_url_is_toLong, CommonContants.common_error_params_code);
|
|
|
}
|
|
|
if(StringUtils.isEmpty(wxMenu.getAppid())){
|
|
|
throw new ApiException(WxContants.WxMenu.message_fail_appid_is_null, CommonContants.common_error_params_code);
|
|
|
}
|
|
|
if(StringUtils.isEmpty(wxMenu.getPagepath())){
|
|
|
throw new ApiException(WxContants.WxMenu.message_fail_pagepath_is_null, CommonContants.common_error_params_code);
|
|
|
}
|
|
|
}
|
|
|
if("media_id".equals(type)||"view_limited".equals(type)){
|
|
|
if(StringUtils.isEmpty(wxMenu.getMediaId())){
|
|
|
throw new ApiException(WxContants.WxMenu.message_fail_mediaId_is_null, CommonContants.common_error_params_code);
|
|
|
}
|
|
|
}
|
|
|
if(StringUtils.isEmpty(wxMenu.getSort())){
|