|
@ -0,0 +1,208 @@
|
|
|
package com.yihu.jw.base.endpoint.menu;
|
|
|
|
|
|
import com.yihu.jw.base.dao.menu.BaseAppMenuDao;
|
|
|
import com.yihu.jw.base.service.menu.BaseAppMenuService;
|
|
|
import com.yihu.jw.entity.base.menu.BaseAppMenu;
|
|
|
import com.yihu.jw.restmodel.web.Envelop;
|
|
|
import com.yihu.jw.restmodel.web.ListEnvelop;
|
|
|
import com.yihu.jw.restmodel.web.ObjEnvelop;
|
|
|
import com.yihu.jw.restmodel.web.endpoint.EnvelopRestEndpoint;
|
|
|
import io.swagger.annotations.Api;
|
|
|
import io.swagger.annotations.ApiOperation;
|
|
|
import io.swagger.annotations.ApiParam;
|
|
|
import org.apache.commons.lang3.StringUtils;
|
|
|
import org.springframework.web.bind.annotation.RequestMapping;
|
|
|
import org.springframework.web.bind.annotation.RequestParam;
|
|
|
import org.springframework.web.bind.annotation.RestController;
|
|
|
|
|
|
import javax.annotation.Resource;
|
|
|
import java.util.ArrayList;
|
|
|
import java.util.HashMap;
|
|
|
import java.util.List;
|
|
|
import java.util.Map;
|
|
|
|
|
|
/**
|
|
|
* app应用管理,按报表分类来做
|
|
|
* Created by yeshijie on 2022/9/27.
|
|
|
*/
|
|
|
@RestController
|
|
|
@RequestMapping(value = "appMenu")
|
|
|
@Api(value = "app菜单管理", tags = {"基础服务 - app菜单管理"})
|
|
|
public class BaseAppMenuEndPoint extends EnvelopRestEndpoint {
|
|
|
|
|
|
@Resource
|
|
|
private BaseAppMenuService baseAppMenuService;
|
|
|
@Resource
|
|
|
private BaseAppMenuDao baseAppMenuDao;
|
|
|
|
|
|
public static Map<Integer,String> isTopName = new HashMap<>();
|
|
|
public static Map<Integer,String> statusName = new HashMap<>();
|
|
|
static {
|
|
|
isTopName.put(1,"是");
|
|
|
isTopName.put(0,"否");
|
|
|
isTopName.put(null,"否");
|
|
|
|
|
|
statusName.put(1,"生效");
|
|
|
statusName.put(0,"失效");
|
|
|
statusName.put(null,"失效");
|
|
|
}
|
|
|
|
|
|
|
|
|
@RequestMapping("/save")
|
|
|
@ApiOperation(value = "保存或修改")
|
|
|
public Envelop save(@ApiParam(name = "data", value = "data",required = true)
|
|
|
@RequestParam(value = "data") String data) {
|
|
|
try {
|
|
|
String rsReportCategory = data;
|
|
|
BaseAppMenu newBaseApp = toEntity(rsReportCategory, BaseAppMenu.class);
|
|
|
if (StringUtils.isEmpty(newBaseApp.getCode())) {
|
|
|
return failed("编码不能为空!");
|
|
|
}
|
|
|
if (StringUtils.isEmpty(newBaseApp.getName())) {
|
|
|
return failed("名称不能为空!");
|
|
|
}
|
|
|
|
|
|
if (newBaseApp.getId() == null) {
|
|
|
// 新增
|
|
|
if (null == newBaseApp.getPid()) {
|
|
|
newBaseApp.setPid("0");
|
|
|
}
|
|
|
if (null == newBaseApp.getSort()) {
|
|
|
newBaseApp.setSort(99);
|
|
|
}
|
|
|
//新增判断名称和code 是否唯一
|
|
|
if(!baseAppMenuService.isUniqueCode("0", newBaseApp.getCode())){
|
|
|
return ObjEnvelop.getError("编码已存在",-1);
|
|
|
}
|
|
|
|
|
|
baseAppMenuDao.save(newBaseApp);
|
|
|
return ObjEnvelop.getSuccess("操作成功",newBaseApp);
|
|
|
} else {
|
|
|
//修改 如果有修改name和code要判断是否唯一
|
|
|
BaseAppMenu oldBaseApp = baseAppMenuDao.findById(newBaseApp.getId()).orElse(null);
|
|
|
if (oldBaseApp==null){
|
|
|
return failed("id错误");
|
|
|
}
|
|
|
|
|
|
if(!oldBaseApp.getCode().equals(newBaseApp.getCode())){
|
|
|
if(!baseAppMenuService.isUniqueCode(newBaseApp.getId(), newBaseApp.getCode())){
|
|
|
return ObjEnvelop.getError("编码已存在",-1);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
oldBaseApp.setCode(newBaseApp.getCode());
|
|
|
oldBaseApp.setName(newBaseApp.getName());
|
|
|
oldBaseApp.setPid(newBaseApp.getPid());
|
|
|
oldBaseApp.setSort(null == newBaseApp.getSort() ? 99 : newBaseApp.getSort());
|
|
|
oldBaseApp.setRemark(newBaseApp.getRemark());
|
|
|
oldBaseApp.setIsTop(newBaseApp.getIsTop());
|
|
|
oldBaseApp.setStatus(newBaseApp.getStatus());
|
|
|
oldBaseApp.setImg(newBaseApp.getImg());
|
|
|
oldBaseApp.setUrl(newBaseApp.getUrl());
|
|
|
baseAppMenuDao.save(oldBaseApp);
|
|
|
return ObjEnvelop.getSuccess("操作成功",oldBaseApp);
|
|
|
}
|
|
|
} catch (Exception e) {
|
|
|
e.printStackTrace();
|
|
|
return failed("操作失败");
|
|
|
}
|
|
|
}
|
|
|
|
|
|
|
|
|
@RequestMapping("/delete")
|
|
|
@ApiOperation(value = "删除")
|
|
|
public Envelop delete(@ApiParam(name = "id", value = "id",required = true)
|
|
|
@RequestParam(value = "id") String id) {
|
|
|
try {
|
|
|
baseAppMenuDao.deleteById(id);
|
|
|
return success("删除成功");
|
|
|
} catch (Exception e) {
|
|
|
e.printStackTrace();
|
|
|
return failed("删除失败");
|
|
|
}
|
|
|
}
|
|
|
|
|
|
@RequestMapping("/getComboTreeData")
|
|
|
@ApiOperation(value = "获取资源报表分类下拉框数据")
|
|
|
public Envelop getComboTreeData() {
|
|
|
try {
|
|
|
List<BaseAppMenu> list = baseAppMenuDao.findAll();
|
|
|
list.forEach(one->{
|
|
|
one.setIsTopName(isTopName.get(one.getIsTop()));
|
|
|
one.setStatusName(statusName.get(one.getStatus()));
|
|
|
});
|
|
|
return ListEnvelop.getSuccess ("查询成功",list);
|
|
|
} catch (Exception e) {
|
|
|
e.printStackTrace();
|
|
|
return failed("查询失败");
|
|
|
}
|
|
|
}
|
|
|
|
|
|
@RequestMapping(value = "detail")
|
|
|
@ApiOperation(value = "获取详情")
|
|
|
public Envelop detail(@ApiParam(name = "id", value = "id",required = true)
|
|
|
@RequestParam(value = "id") String id) {
|
|
|
try {
|
|
|
BaseAppMenu one = baseAppMenuDao.findById(id).orElse(null);
|
|
|
if(one == null){
|
|
|
return failed("查询失败");
|
|
|
}
|
|
|
one.setIsTopName(isTopName.get(one.getIsTop()));
|
|
|
one.setStatusName(statusName.get(one.getStatus()));
|
|
|
return ObjEnvelop.getSuccess("查询成功",one);
|
|
|
} catch (Exception e) {
|
|
|
e.printStackTrace();
|
|
|
return failed("查询失败");
|
|
|
}
|
|
|
}
|
|
|
|
|
|
@RequestMapping("/getTreeData")
|
|
|
@ApiOperation(value = "根据条件,获取菜单列表(树形结构)")
|
|
|
public Envelop getTreeData(@ApiParam(name = "codeName", value = "codeName")
|
|
|
@RequestParam(value = "codeName",required = false) String codeName) {
|
|
|
try {
|
|
|
List<BaseAppMenu> resultList = new ArrayList<>();
|
|
|
|
|
|
// 获取最顶层的资源报表分类集合
|
|
|
List<BaseAppMenu> topNodeList = baseAppMenuService.getChildrenByPid(BaseAppMenu.topPid);
|
|
|
if (topNodeList.size() == 0) {
|
|
|
return success("查询成功");
|
|
|
}
|
|
|
|
|
|
// 暂存最顶层资源报表分类中,满足条件的集合
|
|
|
List<BaseAppMenu> topNodeListIn = new ArrayList<>();
|
|
|
// 暂存最顶层资源报表分类中,不满足条件的集合
|
|
|
List<BaseAppMenu> topNodeListOut = new ArrayList<>();
|
|
|
|
|
|
if (StringUtils.isEmpty(codeName)) {
|
|
|
List<BaseAppMenu> treeList = baseAppMenuService.getTreeByParents(topNodeList);
|
|
|
return ListEnvelop.getSuccess("查询成功",treeList);
|
|
|
}
|
|
|
|
|
|
for (BaseAppMenu reportCategory : topNodeList) {
|
|
|
if (reportCategory.getCode().contains(codeName) || reportCategory.getName().contains(codeName)) {
|
|
|
topNodeListIn.add(reportCategory);
|
|
|
continue;
|
|
|
}
|
|
|
topNodeListOut.add(reportCategory);
|
|
|
}
|
|
|
if (topNodeListIn.size() != 0) {
|
|
|
List<BaseAppMenu> inList = baseAppMenuService.getTreeByParents(topNodeListIn);
|
|
|
resultList.addAll(inList);
|
|
|
}
|
|
|
List<BaseAppMenu> outList = baseAppMenuService.getTreeByParentsAndCodeName(topNodeListOut, codeName);
|
|
|
resultList.addAll(outList);
|
|
|
|
|
|
resultList.forEach(one->{
|
|
|
one.setIsTopName(isTopName.get(one.getIsTop()));
|
|
|
one.setStatusName(statusName.get(one.getStatus()));
|
|
|
});
|
|
|
|
|
|
return ListEnvelop.getSuccess("查询成功",resultList);
|
|
|
} catch (Exception ex) {
|
|
|
ex.printStackTrace();
|
|
|
return failed("查询失败");
|
|
|
}
|
|
|
}
|
|
|
|
|
|
}
|