This repository has been archived on 2025-09-14. You can view files and clone it, but cannot push or open issues or pull requests.
Files
k18-ntcs-web-ntc/src/main/java/com/nis/web/controller/specific/SpecificServiceCfgController.java

290 lines
9.3 KiB
Java
Raw Normal View History

2018-03-17 17:09:19 +08:00
package com.nis.web.controller.specific;
import java.util.List;
import java.util.Map;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.shiro.authz.annotation.Logical;
2018-03-17 17:09:19 +08:00
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.mvc.support.RedirectAttributes;
import com.google.common.collect.Lists;
import com.google.common.collect.Maps;
import com.nis.domain.Page;
import com.nis.domain.specific.SpecificServiceCfg;
import com.nis.util.StringUtil;
import com.nis.util.StringUtils;
import com.nis.web.controller.BaseController;
@Controller
@RequestMapping(value = "${adminPath}/specific/specificServiceCfg")
public class SpecificServiceCfgController extends BaseController {
/* @ModelAttribute
public SpecificServiceCfg get(@RequestParam(required=false)Integer specServiceId) {
if (!StringUtil.isEmpty(specServiceId)) {
SpecificServiceCfg ss = specificServiceCfgService.getBySpecServiceId(specServiceId);
return ss==null?new SpecificServiceCfg():ss;
} else {
return new SpecificServiceCfg();
}
}*/
/**
* 查出分页列表
*
* @param specificServiceCfg
* @param request
* @param response
* @param model
* @return
*/
2018-03-28 08:42:32 +08:00
@RequiresPermissions("specific:service:view")
2018-03-17 17:09:19 +08:00
@RequestMapping(value = "list")
public String list(SpecificServiceCfg specificServiceCfg, HttpServletRequest request, HttpServletResponse response,
Model model) {
String searchType = null;
String searchContent = null;
if(specificServiceCfg.getSpecServiceId()!=null){
searchType = "specServiceId";
searchContent = specificServiceCfg.getSpecServiceId().toString();
}
if(!StringUtils.isBlank(specificServiceCfg.getSpecServiceName())){
searchType = "specServiceName";
searchContent = specificServiceCfg.getSpecServiceName();
}
if(!StringUtils.isBlank(specificServiceCfg.getSpecServiceDesc())){
searchType = "specServiceDesc";
searchContent = specificServiceCfg.getSpecServiceDesc();
}
if(specificServiceCfg.getGroupId()!=null){
searchType = "groupId";
searchContent = specificServiceCfg.getGroupId().toString();
}
2018-03-17 17:09:19 +08:00
model.addAttribute("searchType", searchType);
model.addAttribute("searchContent", searchContent);
Page<SpecificServiceCfg> pageCondition = new Page<SpecificServiceCfg>(request, response);
2018-03-17 17:09:19 +08:00
// 取出所有符合条件的数据
List<SpecificServiceCfg> allList = specificServiceCfgService.findAllSpecificServiceCfg(specificServiceCfg,pageCondition.getOrderBy());
2018-03-17 17:09:19 +08:00
model.addAttribute("showTotalCount", allList.size());
// 取出所有符合条件的顶层分页
Page<SpecificServiceCfg> page = specificServiceCfgService
.findTopPage(pageCondition, specificServiceCfg);
2018-03-17 17:09:19 +08:00
// 植入序号
for (int i = 0; i < page.getList().size(); i++) {
page.getList().get(i).setShowSequence("" + (i + 1 + ((page.getPageNo() - 1) * page.getPageSize())));
}
model.addAttribute("page", page);
2018-03-28 08:42:32 +08:00
// 删除顶层数据、取出id
2018-03-17 17:09:19 +08:00
List<Integer> intList = Lists.newArrayList();
for (SpecificServiceCfg tempSS : page.getList()) {
if (tempSS != null) {
intList.add(tempSS.getSpecServiceId());
}
}
for (int i = allList.size() - 1; i >= 0; i--) {
SpecificServiceCfg ss = allList.get(i);
if ((ss != null && intList.contains(ss.getSpecServiceId())) || (ss != null && ss.getParent().getSpecServiceId() == 0)) {
2018-03-17 17:09:19 +08:00
allList.remove(ss);
}
}
allList.addAll(page.getList());
2018-03-17 17:09:19 +08:00
List<SpecificServiceCfg> list = Lists.newArrayList();
SpecificServiceCfg.sortList(list, allList, 0, true);
//处理下级序号
SpecificServiceCfg.addChildrenSeq(list, 0);
model.addAttribute("list", list);
return "/specific/specificServiceCfgList";
}
/**
* 进入查看或新增修改页面
*
* @param specificServiceCfg
* @param model
* @param doAction
* @param mulitId
* @return
*/
@RequiresPermissions(value={"specific:service:add","specific:service:edit","specific:service:view"},logical=Logical.OR)
2018-03-17 17:09:19 +08:00
@RequestMapping(value = { "form" })
public String form(SpecificServiceCfg specificServiceCfg, Model model, String doAction) {
if(specificServiceCfg!=null&&specificServiceCfg.getSpecServiceId()!=null){
specificServiceCfg = specificServiceCfgService.getBySpecServiceId(specificServiceCfg.getSpecServiceId());
2018-03-17 17:09:19 +08:00
}
if (specificServiceCfg == null || specificServiceCfg.getSpecServiceId()==null) {
2018-03-17 17:09:19 +08:00
SpecificServiceCfg parent = new SpecificServiceCfg();
parent.setSpecServiceId(0);
specificServiceCfg.setParent(parent);
}
model.addAttribute("specificServiceCfg", specificServiceCfg);
if (doAction != null && doAction.equals("0")) {
return "/specific/specificServiceCfgInfo";
}
return "/specific/specificServiceCfgForm";
}
/**
* 新增或保存
* @param specificServiceCfg
* @param model
* @param redirectAttributes
* @return
*/
@RequiresPermissions(value= {"specific:service:add","specific:service:edit"},logical=Logical.OR)
2018-03-17 17:09:19 +08:00
@RequestMapping(value="saveOrUpdate")
public String saveOrUpdate(SpecificServiceCfg specificServiceCfg, Model model,
RedirectAttributes redirectAttributes) {
2018-03-17 17:09:19 +08:00
try {
specificServiceCfgService.saveOrUpdate(specificServiceCfg);
addMessage(redirectAttributes, "save_success");
2018-03-17 17:09:19 +08:00
} catch (Exception e) {
e.printStackTrace();
addMessage(redirectAttributes, "save_failed");
2018-03-17 17:09:19 +08:00
}
return "redirect:" + adminPath + "/specific/specificServiceCfg/list";
}
/**
* 删除
* @param specificServiceCfg
* @param redirectAttributes
* @param mulitId
* @return
*/
@RequiresPermissions("specific:service:del")
2018-03-17 17:09:19 +08:00
@RequestMapping(value="delete")
public String delete(SpecificServiceCfg specificServiceCfg, RedirectAttributes redirectAttributes, String mulitId){
try{
specificServiceCfgService.delete(mulitId);
addMessage(redirectAttributes,"delete_success");
2018-03-17 17:09:19 +08:00
}catch (Exception e){
e.printStackTrace();
addMessage(redirectAttributes,"delete_failed");
2018-03-17 17:09:19 +08:00
}
return "redirect:"+adminPath+"/specific/specificServiceCfg/list";
}
/**
* 父节点选择树形结构
* @param extId排除节点id
2018-03-17 17:09:19 +08:00
* @param isShowHide
* @param isLeafShow:叶子节点是否显示
2018-03-17 17:09:19 +08:00
* @param response
* @return
*/
@ResponseBody
@RequestMapping(value = "treeData")
public List<Map<String, Object>> treeData(@RequestParam(required=false) String extId,@RequestParam(required=false) String isShowHide,
@RequestParam(required=false)boolean isLeafShow,HttpServletResponse response){
2018-03-17 17:09:19 +08:00
List<Map<String, Object>> mapList = Lists.newArrayList();
Map<String, Object> map2 = Maps.newHashMap();
map2.put("id", 0);
map2.put("pId", 0);
map2.put("name","root_node");
2018-03-17 17:09:19 +08:00
//map2.put("placeholder","0");
mapList.add(map2);
List<SpecificServiceCfg> list = specificServiceCfgService.findAllSpecificServiceCfg(new SpecificServiceCfg(),"");
2018-03-17 17:09:19 +08:00
for (int i=0; i<list.size(); i++){
SpecificServiceCfg specificServiceCfg = list.get(i);
if(StringUtils.isBlank(extId)||(extId!=null&&!extId.equals(specificServiceCfg.getSpecServiceId().toString()))){
if(specificServiceCfg.getIsValid().equals(0)||
(!isLeafShow && specificServiceCfg.getIsLeaf().equals(1))){
2018-03-17 17:09:19 +08:00
continue;
}
Map<String, Object> map = Maps.newHashMap();
map.put("id", specificServiceCfg.getSpecServiceId());
map.put("pId", specificServiceCfg.getParent().getSpecServiceId());
map.put("name",specificServiceCfg.getSpecServiceName());
mapList.add(map);
}
}
return mapList;
}
/**
* 校验协议id是否重复
* @param specServiceId
* @param oldId
* @return
*/
@ResponseBody
@RequestMapping(value = "isIdRepeat")
public boolean isIdRepeat(String specServiceId,String oldId){
if(oldId!=null){
if(oldId.trim().equals(specServiceId)){
return true;
}
2018-03-17 17:09:19 +08:00
}
if(specServiceId!=null){
SpecificServiceCfg ss = specificServiceCfgService.getBySpecServiceId(Integer.valueOf(specServiceId));
if(ss==null){
return true;
}
}
return false;
}
/**
* 校验叶子节点无上级不得选为叶子节点
* @param specServiceId
* @param oldId
* @return
*/
@ResponseBody
@RequestMapping(value = "ajaxLeafHasTree")
public boolean ajaxLeafHasTree(Integer parentId, Integer newIsLeaf){
if(parentId==null||parentId==0){
if(newIsLeaf==0){
return true;
}
}
if(parentId!=null&parentId!=0){
return true;
}
return false;
}
/**
* 校验叶子节点有下级不得更改为叶子节点
* @param parent
* @param newIsLeaf
* @return
*/
@ResponseBody
@RequestMapping(value = "ajaxLeafChange")
public boolean ajaxLeafChange(Integer parent,Integer newIsLeaf){
if(parent==null){
return true;
}
List<SpecificServiceCfg> list = specificServiceCfgService.getChildrenById(parent);
if(list==null||list.size()==0){
2018-03-17 17:09:19 +08:00
return true;
}else{
if(newIsLeaf==0){
return true;
}
}
return false;
}
}