|
@@ -1,10 +1,68 @@
|
|
|
package com.judong.chuanyiserver.service.impl;
|
|
|
|
|
|
+import com.alibaba.fastjson.JSONObject;
|
|
|
+import com.judong.chuanyiserver.dao.MenuDao;
|
|
|
+import com.judong.chuanyiserver.entity.Menu;
|
|
|
+import com.judong.chuanyiserver.enums.ResultEnum;
|
|
|
import com.judong.chuanyiserver.service.MenuService;
|
|
|
+import com.judong.chuanyiserver.util.Blank;
|
|
|
+import com.judong.chuanyiserver.util.ConstantStr;
|
|
|
+import com.judong.chuanyiserver.util.Result;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
|
|
|
+import java.util.List;
|
|
|
+
|
|
|
@Service
|
|
|
@Transactional
|
|
|
public class MenuServiceImpl implements MenuService {
|
|
|
+ @Autowired
|
|
|
+ private MenuDao menuDao;
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public synchronized Result addMenu(Menu menu) {
|
|
|
+ if (Blank.isEmpty(menu.getParentId(), menu.getMenuName(), menu.getMenuUrl())) {
|
|
|
+ return Result.no(ResultEnum.REQUEST_WRONGPARAMS.getRespCode(), "父id,菜单名称,菜单路径不能为空");
|
|
|
+ }
|
|
|
+ if (Blank.isEmpty(menuDao.getMenuByUrl(menu.getMenuUrl()))) {
|
|
|
+ return Result.no(ResultEnum.REQUEST_WRONGPARAMS.getRespCode(), "该菜单路径已被使用,请更换其他菜单路径");
|
|
|
+ }
|
|
|
+ //新增菜单,默认为可用
|
|
|
+ menu.setMenuStatus(ConstantStr.MENU_AVAILABLE);
|
|
|
+ if (menuDao.addMenu(menu) <= 0) {
|
|
|
+ return Result.no(ResultEnum.SERVER_ERROR.getRespCode(), "新增失败");
|
|
|
+ }
|
|
|
+ return Result.ok("添加菜单成功");
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public Result updateMenu(Menu menu) {
|
|
|
+ if (Blank.isEmpty(menu.getId(), menu.getParentId(), menu.getMenuName(), menu.getMenuUrl())) {
|
|
|
+ return Result.no(ResultEnum.REQUEST_WRONGPARAMS.getRespCode(), "id,父id,菜单名称,菜单路径不能为空");
|
|
|
+ }
|
|
|
+ if (Blank.isNotEmpty(menuDao.getMenuByNoIdUrl(menu.getId(), menu.getMenuUrl()))) {
|
|
|
+ return Result.no(ResultEnum.REQUEST_WRONGPARAMS.getRespCode(), "已存在该菜单路径,请更换菜单路径");
|
|
|
+ }
|
|
|
+ if (menuDao.updateMenu(menu) <= 0) {
|
|
|
+ return Result.no(ResultEnum.SERVER_ERROR.getRespCode(), "修改菜单失败");
|
|
|
+ }
|
|
|
+ return Result.ok("修改菜单成功");
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public Result getMenuListByPage(Integer page, Integer limit) {
|
|
|
+ JSONObject jsonObject = new JSONObject();
|
|
|
+ Long count = menuDao.getMenuCount();
|
|
|
+ Long startNum = Long.valueOf((page - 1) * limit);
|
|
|
+ List<Menu> menuList = menuDao.getMenuListByPage(startNum, Long.valueOf(limit));
|
|
|
+ jsonObject.put("count", count);
|
|
|
+ jsonObject.put("menuList", menuList);
|
|
|
+ return Result.ok(jsonObject);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public Result getMenuById(Integer id) {
|
|
|
+ return Result.ok(menuDao.getMenuById(id));
|
|
|
+ }
|
|
|
}
|