package com.landtool.lanbase.modules.res.controller; import java.util.HashMap; import java.util.List; import java.util.Map; import org.apache.shiro.authz.annotation.RequiresPermissions; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Controller; import org.springframework.ui.Model; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.ResponseBody; import com.landtool.lanbase.common.annotation.LogAction; import com.landtool.lanbase.config.SysTemPropertyConfig; import com.landtool.lanbase.modules.log.service.LogActionService; import com.landtool.lanbase.modules.res.entity.Res_Catalog; import com.landtool.lanbase.modules.res.entity.Res_MainInfo; import com.landtool.lanbase.modules.res.entity.Res_OneMap_Catalog; import com.landtool.lanbase.modules.res.entity.Res_OneMap_CatalogResource; import com.landtool.lanbase.modules.res.service.ResCatalogService; import com.landtool.lanbase.modules.res.service.ResMainInfoService; import com.landtool.lanbase.modules.res.service.ResOnemapCatalogResourceService; import com.landtool.lanbase.modules.res.service.ResOnemapCatalogService; import com.landtool.lanbase.modules.sys.controller.AbstractController; /** * @Date: 2018-09-02 * @Description:一张图资源目录编目管理 */ @Controller @RequestMapping("/res/OnemapCatalog") public class ResOnemapCatalogController extends AbstractController { @Autowired private ResMainInfoService resMainInfoService; @Autowired private ResCatalogService resCatalogService; @Autowired private ResOnemapCatalogService resOnemapCatalogService; @Autowired private ResOnemapCatalogResourceService resOnemapCatalogResourceService; @Autowired private SysTemPropertyConfig sysConfig; @Autowired private LogActionService logActionService; @RequestMapping("/onemapIndex") public String onemapIndex(Model model, String type, Integer themeid) { String pubzyWebRoot = sysConfig.getPubzyWebRoot(); model.addAttribute("pubzyWebRoot", pubzyWebRoot); model.addAttribute("systemName", sysConfig.getAppFullName()); model.addAttribute("jspwebroot", pubzyWebRoot.replace("javapubzy/", ""));// 临时处理 model.addAttribute("type", type); model.addAttribute("themeid", themeid); return "/ResManage/ResTheme/catalog/onemapindex"; } @RequestMapping("/index") public String CatalogIndex(Model model, String type) { model.addAttribute("pubzyWebRoot", sysConfig.getPubzyWebRoot()); model.addAttribute("type", type); model.addAttribute("systemName", sysConfig.getAppFullName()); return "/ResManage/ResTheme/catalog/index"; } /** * @Description: 查询目录结构 */ @ResponseBody @RequestMapping("/selectmulu") public String selectDirectoryStructure(int id, String type, int themeid) { Map map = new HashMap(); map.put("parentid", id); map.put("themeid", themeid); map.put("catlogtype", (type.equals("ExtThemeMap") ? "专题地图" : "业务图层")); List resCatalogList = resOnemapCatalogService.selectResCatalogToParentid(map); String resCatalogJson = ""; for (Res_OneMap_Catalog resCatalog : resCatalogList) { Map paramMap = new HashMap(); paramMap.put("catlogid", resCatalog.getCatlogid()); paramMap.put("catlogtype", (type.equals("ExtThemeMap") ? "专题地图" : "业务图层")); paramMap.put("parentid", resCatalog.getCatlogid()); int childCount = resOnemapCatalogService.selectResCatalogIsExistsSon(paramMap) + resOnemapCatalogService.selectMuLuZiYuanCount(paramMap); resCatalogJson += (resCatalogJson.length() > 0 ? "," : "") + "{id:" + resCatalog.getCatlogid() + ", name:'" + resCatalog.getTitle() + "', pId:" + resCatalog.getParentid() + ", rpId:" + resCatalog.getParentid(); if (resCatalog.getIcon() == null || resCatalog.getIcon().length() == 0) { resCatalogJson += (childCount > 0 ? ",isParent:true,iconOpen:'/image/classicons/folderOpen.png',iconClose:'/image/classicons/folder.png'" : ",icon:'/image/classicons/defaulticon.png'") + ", code: '" + resCatalog.getCatlogid() + "'}";//update:dsh(2018/12/05) } else { resCatalogJson += (",isParent:" + (childCount > 0 ? "true" : "false") + ",icon:'" + "/uploadPath/" + resCatalog.getIcon()) + "', code: '" + resCatalog.getCatlogid() + "'}"; } } // 循环构造资源节点 List list = resOnemapCatalogResourceService.getCatalogResourceByCatalogID(id); for (Res_MainInfo resMainInfo1 : list) { if (!"".equals(resCatalogJson.toString())) { resCatalogJson += ","; } resCatalogJson += "{id: 'ZiYuan_" + resMainInfo1.getResourceid() + "',name:'" + resMainInfo1.getTitle() + "', title: '" + resMainInfo1.getDatasources() + "',isParent:false,icon:'/image/classicons/"+resMainInfo1.getResourceclass()+".png'}";//update:dsh(2018/12/05) } return "[" + resCatalogJson + "]"; } /** * @Description: 获取目录信息 */ @ResponseBody @RequiresPermissions("res:catalog:edit") @RequestMapping("/getcataloginfo") public String getCatalogInfo(int id) { Res_OneMap_Catalog resCatalog = resOnemapCatalogService.getResCatalogInfoById(id); String result = ""; if (resCatalog == null) { result = "{ success: true,id:\"0\",name:\"资源目录\",no:0,index:null,beizhu:null,icon:null}"; } else { result = "{ success: true,id:\"" + resCatalog.getCatlogid() + "\",name:\"" + resCatalog.getTitle() + "\",no:\"" + resCatalog.getCatlogid() + "\",index:\"\",beizhu:\"\",icon:\"" + resCatalog.getIcon() + "\"}"; } return result; } /** * @Description: 新增子集页面 */ @ResponseBody @RequestMapping("/addchildren") public String addChildren(int id) { Res_OneMap_Catalog resCatalog = resOnemapCatalogService.getResCatalogInfoById(id); String orderid = ""; if (resCatalog == null) { //根目录的排序ID为0,需要特殊处理 orderid = resOnemapCatalogService.getMaxCATLOGCODEFromMainIndex(0); if (orderid == null) { orderid = "01"; } else { int newOrderid = Integer.valueOf(orderid) + 1; if (newOrderid < 10) { orderid = "0" + String.valueOf(newOrderid); } else { orderid = String.valueOf(newOrderid); } } } else { orderid = resOnemapCatalogService.getMaxOrderId(id); if (orderid == null) { orderid = String.valueOf(resCatalog.getCatlogid()) + "01"; } else { int newOrderid = Integer.valueOf(orderid) + 1; if (orderid.startsWith("0")) { orderid = "0" + String.valueOf(newOrderid); } else { orderid = String.valueOf(newOrderid); } } } Object FatherName = ""; if (id == 0) { //根目录的排序ID为0,需要特殊处理 FatherName = "资源目录"; } else { FatherName = resCatalog.getTitle(); } String resCatalogJson = ""; if (resCatalog == null) { resCatalogJson += "{id:" + 0 + ", name:'" + FatherName + "', pId:" + 0 + ", oId:'" + orderid + "'}"; } else { resCatalogJson += "{id:" + resCatalog.getCatlogid() + ", name:'" + FatherName + "', pId:" + resCatalog.getParentid() + ", oId:'" + orderid + "'}"; } //查询当前父节点的信息 返回到前台 return resCatalogJson; } /** * @Description: 新增子目录方法 */ @ResponseBody @RequiresPermissions("res:catalog:edit") @RequestMapping("/insert") @LogAction("资源管理,资源编目,资源目录新增(子级),新增") public String insert(Res_OneMap_Catalog model) { String orderid = ""; if (model.getParentid() == 0) { //根目录的排序ID为0,需要特殊处理 orderid = resOnemapCatalogService.getMaxOrderIdFromMainIndex(model.getParentid()); if (orderid == null) { orderid = "1"; } else { int newOrderid = Integer.valueOf(orderid) + 1; orderid = String.valueOf(newOrderid); } } else { orderid = resOnemapCatalogService.getMaxOrderId(model.getParentid()); //获取目标目录最大的排序ID if (orderid == null) { Res_OneMap_Catalog resCatalog = resOnemapCatalogService.getResCatalogInfoById(model.getParentid()); orderid = String.valueOf(resCatalog.getOrderid()) + "01"; } else { int newOrderid = Integer.valueOf(orderid) + 1; orderid = String.valueOf(newOrderid); } } model.setOrderid(Integer.valueOf(orderid)); int result = resOnemapCatalogService.insertSelective(model); if (result == 1) { return "新增成功"; } else { return "失败"; } } /** * @Description: 新增同级页面 */ @ResponseBody @RequiresPermissions("res:catalog:edit") @RequestMapping("/addbrother") @LogAction("资源管理,资源编目,资源目录新增(同级),新增") public String addBrother(int id) { Res_OneMap_Catalog resCatalog = resOnemapCatalogService.getResCatalogInfoById(id); int pid = resCatalog.getParentid(); String orderid = ""; if (pid == 0) { //根目录的排序ID为0,需要特殊处理 orderid = resOnemapCatalogService.getMaxCATLOGCODEFromMainIndex(pid); } else { orderid = resOnemapCatalogService.getMaxOrderId(pid); } if (orderid == null) { orderid = String.valueOf(resCatalog.getCatlogid()) + "01"; } else { int newOrderid = Integer.valueOf(orderid) + 1; if (newOrderid < 10) { orderid = "0" + String.valueOf(newOrderid); } else { orderid = String.valueOf(newOrderid); } } Object FatherName = ""; if (pid == 0) { //根目录的排序ID为0,需要特殊处理 FatherName = "资源目录"; } else { FatherName = resOnemapCatalogService.getResCatalogInfoById(resCatalog.getParentid()).getTitle(); } String resCatalogJson = ""; resCatalogJson += "{id:" + resCatalog.getCatlogid() + ", name:'" + FatherName + "', pId:" + resCatalog.getParentid() + ", oId:'" + orderid + "'}"; //查询当前父节点的信息 返回到前台 return resCatalogJson; } /** * @Description: 目录修改页面 */ @ResponseBody @RequiresPermissions("res:catalog:edit") @RequestMapping("/edit") public String edit(int id) { Res_OneMap_Catalog resCatalog = resOnemapCatalogService.getResCatalogInfoById(id); Res_OneMap_Catalog resCatalogf = resOnemapCatalogService.getResCatalogInfoById(resCatalog.getParentid()); //查询需要修改目录的信息返回 String resCatalogJson = ""; if (resCatalogf != null) { resCatalogJson += "{id:" + resCatalog.getCatlogid() + ", name:'" + resCatalog.getTitle() + "', Pid:" + resCatalog.getParentid() + ", firstPY:'', remark:'', icon:'" + resCatalog.getIcon() + "', descrip:'', fname:'" + resCatalogf.getTitle() + "', oId:'" + resCatalog.getCatlogid() + "'}"; } else { resCatalogJson += "{id:" + resCatalog.getCatlogid() + ", name:'" + resCatalog.getTitle() + "', Pid:" + 0 + ", firstPY:'', remark:'', icon:'" + resCatalog.getIcon() + "', descrip:'', fname:'" + "资源目录" + "', oId:'" + resCatalog.getCatlogid() + "'}"; } return resCatalogJson; } /** * @Description: 目录修改方法 */ @ResponseBody @RequiresPermissions("res:catalog:edit") @RequestMapping("/saveedit") @LogAction("资源管理,资源编目,资源目录修改,修改") public String saveEdit(Res_OneMap_Catalog model) { int result = resOnemapCatalogService.updateByPrimaryKeySelective(model); if (result == 1) { return "修改成功"; } else { return "修改失败"; } } /** * 检查删除的目录下是都存在资源 */ @ResponseBody @RequestMapping("/isDelete") public String isDelete(int id, String type) { Map paramMap = new HashMap(); paramMap.put("catlogid", id); paramMap.put("catlogtype", type); Integer resMainInfos = resOnemapCatalogService.selectMuLuZiYuanCount(paramMap); if (resMainInfos > 0) { return "-1"; } else { logActionService.saveLogAction(("资源管理,资源编目,资源目录删除,删除")); int result = resOnemapCatalogService.deleteByPrimaryKey(id); if (result == 1) { return "删除成功"; } else { return "删除失败"; } } } /** * @Description: 目录删除方法 */ @ResponseBody @RequiresPermissions("res:catalog:edit") @RequestMapping("/delete") public String delete(int id, String type) { logActionService.saveLogAction(("资源管理,资源编目,资源目录删除,删除")); Map map = new HashMap(); map.put("catlogid", id); map.put("catlogtype", (type.equals("ExtThemeMap") ? "专题地图" : "业务图层")); int childCount = resOnemapCatalogService.selectMuLuZiYuanCount(map); if (childCount > 0) { DeleteChildNode(id, type); } List catalogs = resOnemapCatalogService.selectCatalogsByid(map); if (catalogs != null) { for (Integer cid : catalogs) { resOnemapCatalogResourceService.deleteByCatlogid(cid); } } int result = resOnemapCatalogService.deleteByPrimaryKey(id); if (result == 1) { return "删除成功"; } else { return "删除失败"; } } public void DeleteChildNode(int id, String type) { Map map = new HashMap(); map.put("parentid", id); map.put("catlogid", id); map.put("catlogtype", (type.equals("ExtThemeMap") ? "专题地图" : "业务图层")); List List = resOnemapCatalogService.selectResCatalogToParentid(map); for (Res_OneMap_Catalog Model : List) { int childCount = resOnemapCatalogService.selectResCatalogIsExistsSon(map); if (childCount > 0) { DeleteChildNode(id, type); } resOnemapCatalogService.deleteByPrimaryKey(Model.getCatlogid()); } } /** * @Description: 编目排序页面 */ @ResponseBody @RequestMapping("/initsort") public String initSort(String id, String type, Integer themeid) { Map paramMap = new HashMap(); paramMap.put("parentid", id); paramMap.put("themeid", themeid); paramMap.put("catlogtype", (type.equals("ExtThemeMap") ? "专题地图" : "业务图层")); List List = resOnemapCatalogService.selectResCatalogToParentid(paramMap); String Result = "{count:" + List.size() + "," + "children:["; for (Res_OneMap_Catalog model : List) { Result = Result + "{id:" + model.getCatlogid() + ",name:'" + model.getTitle() + "'},"; } if (List.size() != 0) { Result = Result.substring(0, Result.length() - 1); } Result = Result + "]}"; return Result; } /** * @Description: 编目排序方法 */ @ResponseBody @RequiresPermissions("res:catalog:edit") @RequestMapping("/sort") @LogAction("资源管理,资源编目,资源目录修改(编目排序),修改") public String sort(String id, int pid, String type) { if (!"".equals(id)) { String[] arr = id.split("\\|");//排序后资源ID列表 for (int i = 0; i < arr.length; i++) { Res_OneMap_Catalog resCatalog = resOnemapCatalogService.selectByPrimaryKey(Integer.parseInt(arr[i])); resCatalog.setOrderid(i); resOnemapCatalogService.updateByPrimaryKeySelective(resCatalog); } } return ""; } /** * @Description: 新增子目录方法 */ @ResponseBody @RequestMapping("/insertCatalogResource") public String insertCatalogResource(String ids, Integer catlogid) { Integer result = 0; String[] idList = ids.split(","); for (int i = 0; i < idList.length; i++) { Res_OneMap_CatalogResource model = new Res_OneMap_CatalogResource(); model.setCatlogid(catlogid); model.setResourceid(Integer.valueOf(idList[i])); result = resOnemapCatalogResourceService.insertSelective(model); } if (result == 1) { return "保存成功"; } else { return "失败"; } } /** * @Description: 获取目录以及所属资源列表 */ @ResponseBody @RequiresPermissions("res:catalog:edit") @RequestMapping("manage/catalog/selectmuluandziyuan") public String selectMuLuAndZiYuan(int id) { //先根据父节点ID获取子目录 List resCatalogList = resCatalogService.selectResCatalogToParentid(id); String resCatalogJson = ""; for (Res_Catalog resCatalog : resCatalogList) { int childCount = resCatalogService.selectResCatalogIsExistsSon(resCatalog.getCatlogid(),null); resCatalogJson += (resCatalogJson.length() > 0 ? "," : "") + "{id:" + resCatalog.getCatlogid() + ", name:'" + resCatalog.getTitle() + "', pId:" + resCatalog.getParentid() + ",isParent:true,check:true,rpId:" + resCatalog.getParentid() + (",iconOpen:'/image/classicons/folderOpen.png',iconClose:'/image/classicons/folder.png'") + "}"; } //获取完子目录后获取资源 List ZyList = resMainInfoService.selectZyByMuLuId(id); for (Res_MainInfo Zymodel : ZyList) { resCatalogJson += (resCatalogJson.length() > 0 ? "," : "") + "{id:" + Zymodel.getResourceid() + ", name:'" + Zymodel.getTitle() + "', pId:" + Zymodel.getCatlogid() + ", rpId:" + Zymodel.getCatlogid() + ",icon:'/image/classicons/defaulticon.png'" + "}";//update:dsh(2018/12/05) } return "[" + resCatalogJson + "]"; } /** * @Description: 资源位置调整方法 */ @ResponseBody @RequiresPermissions("res:catalog:edit") @RequestMapping("manage/catalog/merge") @LogAction("资源管理,资源编目,资源目录修改(资源调整),修改") public String merge(String ids, String fid) { String[] idArr = ids.split(";"); //不修改目录编码,只修改目录ID会导致有些功能的查询只根据目录编码查询出错 //同一资源的目录ID和目录编码会不一致 alert ykm 2018/12/28 Res_Catalog resCatalog = resCatalogService.selectByPrimaryKey(Integer.valueOf(fid)); for (String zyid : idArr) { Res_MainInfo Zymodel = resMainInfoService.selectByPrimaryKey(Integer.valueOf(zyid)); Zymodel.setCatlogcode(resCatalog.getCatlogcode()); Zymodel.setCatlogid(Integer.valueOf(fid)); int result = resMainInfoService.updateByPrimaryKeySelective(Zymodel); } return "调整成功"; } /** * @Description: 目录拖拉方法 */ @ResponseBody @RequestMapping("manage/catalog/changebianmu") @LogAction("资源管理,资源编目,资源目录修改(拖拉),修改") public String changeBianMu(String id, String newfid) { changeBianMuMethod(id, newfid); return "调整成功!"; } /** * @Description: 主目录调整方法 */ public void changeBianMuMethod(String id, String newfid) { Res_Catalog model = resCatalogService.getResCatalogInfoById(Integer.valueOf(id)); Integer rpid = model.getParentid(); Res_Catalog modelf = new Res_Catalog(); if (newfid.equals("0")) { modelf.setTitle("资源目录"); modelf.setOrderid(0); modelf.setCatlogcode("0"); } else { modelf = resCatalogService.getResCatalogInfoById(Integer.valueOf(newfid)); } model.setParentid(Integer.valueOf(newfid)); //首先更新新的父节点 String neworderid = ""; if (model.getParentid() == 0) { //根目录的排序ID为0,需要特殊处理 neworderid = resCatalogService.getMaxOrderIdFromMainIndex(model.getParentid()); } else { neworderid = resCatalogService.getMaxOrderId(model.getParentid()); } if (neworderid == null) { //如果当前目录下无子目录,则父目录排序+01 Res_Catalog resCatalog = resCatalogService.getResCatalogInfoById(model.getParentid()); neworderid = String.valueOf(modelf.getOrderid()) + "01"; } else { //有子目录则+1 int newOrderid = Integer.valueOf(neworderid) + 1; neworderid = String.valueOf(newOrderid); } //目录编码同样处理 String newcatlogcode = ""; if (model.getParentid() == 0) { newcatlogcode = resCatalogService.getMaxCATLOGCODEFromMainIndex(model.getParentid()); if (newcatlogcode == null) { newcatlogcode = "01"; } else { int newCid = Integer.valueOf(newcatlogcode) + 1; newcatlogcode = "0" + String.valueOf(newCid); } } else { newcatlogcode = resCatalogService.getMaxCATLOGCODE(model.getParentid()); if (newcatlogcode == null) { newcatlogcode = String.valueOf(modelf.getCatlogcode()) + "01"; } else { int newCode = Integer.valueOf(newcatlogcode) + 1; newcatlogcode = "0" + String.valueOf(newCode); } } model.setCatlogcode(newcatlogcode); model.setOrderid(Integer.valueOf(neworderid)); resCatalogService.updateByPrimaryKeySelective(model); List ZyList = resMainInfoService.selectZyByMuLuId(model.getCatlogid()); //更新本目录下所属资源的编码 for (Res_MainInfo ChZymodel : ZyList) { ChZymodel.setCatlogcode(model.getCatlogcode()); resMainInfoService.updateByPrimaryKeySelective(ChZymodel); } //如果有子目录,则更新子目录 int childCount = resCatalogService.selectResCatalogIsExistsSon(model.getCatlogid(),null); if (childCount > 0) { updateChildNode(model.getCatlogid()); } //更新完子目录后,更新原目录的编码与排序,防止错乱 updateOriginal(rpid); } /** * @Description: 子目录调整方法 */ public void updateChildNode(int id) { List List = resCatalogService.selectResCatalogToParentid(id); for (Res_Catalog Cmodel : List) { //循环处理每个子目录的编码和排序 Res_Catalog modelf = resCatalogService.getResCatalogInfoById(id); String newcatlogcode = resCatalogService.getMaxCATLOGCODE(modelf.getCatlogid()); if (newcatlogcode == null) { newcatlogcode = String.valueOf(modelf.getCatlogcode()) + "01"; } else { String Pcatlogcode = String.valueOf(modelf.getCatlogcode()); if (newcatlogcode.length() > Pcatlogcode.length()) { newcatlogcode = newcatlogcode.substring(0, Pcatlogcode.length()); } else { Pcatlogcode = Pcatlogcode.substring(0, newcatlogcode.length()); } if (newcatlogcode.equals(Pcatlogcode)) { newcatlogcode = "0" + String.valueOf(Integer.valueOf(resCatalogService.getMaxCATLOGCODE(modelf.getCatlogid())) + 1); } else { newcatlogcode = String.valueOf(modelf.getCatlogcode()) + "01"; } } Cmodel.setCatlogcode(newcatlogcode); String neworderid = resCatalogService.getMaxOrderId(modelf.getCatlogid()); if (neworderid == null) { neworderid = String.valueOf(modelf.getOrderid()) + "01"; } else { String Porderid = String.valueOf(modelf.getOrderid()); if (neworderid.length() > Porderid.length()) { neworderid = neworderid.substring(0, Porderid.length()); } else { Porderid = Porderid.substring(0, neworderid.length()); } if (neworderid.equals(Porderid)) { neworderid = String.valueOf(Integer.valueOf(resCatalogService.getMaxOrderId(modelf.getCatlogid())) + 1); } else { neworderid = String.valueOf(modelf.getOrderid()) + "01"; } } Cmodel.setOrderid(Integer.valueOf(neworderid)); resCatalogService.updateByPrimaryKeySelective(Cmodel); List ZyList = resMainInfoService.selectZyByMuLuId(Cmodel.getCatlogid()); //更新所属资源的编码 for (Res_MainInfo ChZymodel : ZyList) { ChZymodel.setCatlogcode(Cmodel.getCatlogcode()); resMainInfoService.updateByPrimaryKeySelective(ChZymodel); } int childCount = resCatalogService.selectResCatalogIsExistsSon(Cmodel.getCatlogid(),null); if (childCount > 0) { //如果子目录下还有下级目录,则再次循环此方法 updateChildNode(Cmodel.getCatlogid()); } } } /** * @Description: 原目录调整方法 */ public void updateOriginal(int id) { Res_Catalog model = new Res_Catalog(); if (id == 0) { model.setTitle("资源目录"); model.setOrderid(Integer.valueOf(0)); model.setCatlogcode(""); } else { model = resCatalogService.getResCatalogInfoById(id); } //预先定义目录的第一个编码和排序ID String minCode = String.valueOf(model.getCatlogcode()); minCode = minCode + "01"; String minOrderid = String.valueOf(model.getOrderid()); minOrderid = minOrderid + "01"; int i = 0; List Childrens = resCatalogService.selectResCatalogToParentid(id); //查询目录下所有子目录 for (Res_Catalog item : Childrens) { if (i == 0) { //第一个子目录使用定义的编码和排序ID item.setCatlogcode(minCode); item.setOrderid(Integer.valueOf(minOrderid)); resCatalogService.updateByPrimaryKeySelective(item); i++; } else { //第二个以后的目录则是在第一个目录的编码和排序ID基础上+1 String newCode = ""; if (id == 0) { newCode = resCatalogService.getMinCATLOGCODEFromMainIndex(id); newCode = "0" + String.valueOf(Integer.valueOf(newCode) + i); } else { newCode = resCatalogService.getMinCATLOGCODE(id); newCode = "0" + String.valueOf(Integer.valueOf(newCode) + i); } String newOid = ""; if (id == 0) { newOid = resCatalogService.getMinOrderIdFromMainIndex(id); } else { newOid = resCatalogService.getMinOrderId(id); } newOid = String.valueOf(Integer.valueOf(newOid) + i); item.setOrderid(Integer.valueOf(newOid)); item.setCatlogcode(newCode); resCatalogService.updateByPrimaryKeySelective(item); List ZyList = resMainInfoService.selectZyByMuLuId(item.getCatlogid()); //更新所属资源 for (Res_MainInfo ChZymodel : ZyList) { ChZymodel.setCatlogcode(item.getCatlogcode()); resMainInfoService.updateByPrimaryKeySelective(ChZymodel); } i++; } int childCount = resCatalogService.selectResCatalogIsExistsSon(item.getCatlogid(),null); if (childCount > 0) { //如果含有子目录,则一并更新 updateOriginal(item.getCatlogid()); } } } /** * @Description: 资源排序方法 */ @ResponseBody @RequiresPermissions("res:catalog:edit") @RequestMapping("manage/catalog/zysort") @LogAction("资源管理,资源编目,资源目录修改(资源排序),修改") public String zySort(String ids, Integer pid) { if (!"".equals(ids)) { String[] arr = ids.split("\\|");//排序后资源ID列表 //更新资源排序 for (int i = 0; i < arr.length; i++) { Res_MainInfo resMainInfo = resMainInfoService.selectByPrimaryKey(Integer.parseInt(arr[i])); resMainInfo.setOrderid(i); resMainInfoService.updateByPrimaryKeySelective(resMainInfo); } } List List = resMainInfoService.selectZyByMuLuId(pid); String Result = "{count:" + List.size() + "," + "children:["; for (Res_MainInfo model : List) { Result = Result + "{id:" + model.getResourceid() + ",name:'" + model.getTitle() + "'},"; } if (List.size() != 0) { Result = Result.substring(0, Result.length() - 1); } Result = Result + "]}"; return Result; } /** * @Description: 编目上移方法 */ public int UpSort(int id, int pid) { List List = resCatalogService.selectResCatalogToParentid(pid); int index = -1; for (Res_Catalog model : List) { if (model.getCatlogid() == id) { if (index == -1) { return 0; } else { //当前目录的排序ID和前一个交换 int newoid = List.get(index).getOrderid(); List.get(index).setOrderid(model.getOrderid()); model.setOrderid(newoid); resCatalogService.updateByPrimaryKeySelective(model); resCatalogService.updateByPrimaryKeySelective(List.get(index)); int childCount = resCatalogService.selectResCatalogIsExistsSon(model.getCatlogid(),null); if (childCount > 0) { updateChildrenOid(model.getCatlogid()); } int childCount1 = resCatalogService.selectResCatalogIsExistsSon(List.get(index).getCatlogid(),null); if (childCount1 > 0) { //子目录自动修改 updateChildrenOid(List.get(index).getCatlogid()); } } } index++; } return 1; } /** * @Description: 编目下移方法 */ public int DownSort(int id, int pid) { List List = resCatalogService.selectResCatalogToParentid(pid); int index = 1; for (Res_Catalog model : List) { if (model.getCatlogid() == id) { if (index >= List.size()) { return 0; } else { //当前目录的排序ID和后一个交换 int newoid = List.get(index).getOrderid(); List.get(index).setOrderid(model.getOrderid()); model.setOrderid(newoid); resCatalogService.updateByPrimaryKeySelective(model); resCatalogService.updateByPrimaryKeySelective(List.get(index)); int childCount = resCatalogService.selectResCatalogIsExistsSon(model.getCatlogid(),null); if (childCount > 0) { updateChildrenOid(model.getCatlogid()); } int childCount1 = resCatalogService.selectResCatalogIsExistsSon(List.get(index).getCatlogid(),null); if (childCount1 > 0) { //子目录自动修改 updateChildrenOid(List.get(index).getCatlogid()); } } } index++; } return 1; } /** * @Description: 目录顶置方法 */ public int TopSort(int id, int pid) { List List = resCatalogService.selectResCatalogToParentid(pid); int index = 0; for (Res_Catalog model : List) { //当前目录的排序ID和第一个交换,从第一个到当前目录的所有目录依次往后退一位 if (model.getCatlogid() == id) { if (index == 0) { return 0; } else { int newoid = List.get(0).getOrderid(); for (int i = 0; i <= index - 1; i++) { List.get(i).setOrderid(List.get(i + 1).getOrderid()); resCatalogService.updateByPrimaryKeySelective(List.get(i)); int childCount = resCatalogService.selectResCatalogIsExistsSon(List.get(i).getCatlogid(),null); if (childCount > 0) { updateChildrenOid(List.get(i).getCatlogid()); } } model.setOrderid(newoid); resCatalogService.updateByPrimaryKeySelective(model); int childCount1 = resCatalogService.selectResCatalogIsExistsSon(model.getCatlogid(),null); if (childCount1 > 0) { //子目录自动修改 updateChildrenOid(model.getCatlogid()); } } } index++; } return 1; } /** * @Description: 目录底置方法 */ public int BottomSort(int id, int pid) { List List = resCatalogService.selectResCatalogToParentid(pid); int index = 0; for (Res_Catalog model : List) { //当前目录的排序ID和最后一个交换,从最后一个到当前目录的所有目录依次往前进一位 if (model.getCatlogid() == id) { if (index >= List.size()) { return 0; } else { int newoid = List.get(List.size() - 1).getOrderid(); for (int i = List.size() - 1; i >= index + 1; i--) { List.get(i).setOrderid(List.get(i - 1).getOrderid()); resCatalogService.updateByPrimaryKeySelective(List.get(i)); int childCount = resCatalogService.selectResCatalogIsExistsSon(List.get(i).getCatlogid(),null); if (childCount > 0) { updateChildrenOid(List.get(i).getCatlogid()); } } model.setOrderid(newoid); resCatalogService.updateByPrimaryKeySelective(model); int childCount1 = resCatalogService.selectResCatalogIsExistsSon(model.getCatlogid(),null); if (childCount1 > 0) { //子目录自动修改 updateChildrenOid(model.getCatlogid()); } } } index++; } return 1; } /** * @Description: 子目录自动拍戏方法 */ public void updateChildrenOid(int pid) { Res_Catalog pmodel = resCatalogService.getResCatalogInfoById(pid); List List = resCatalogService.selectResCatalogToParentid(pid); for (Res_Catalog model : List) { String neworderid = ""; neworderid = resCatalogService.getMaxOrderId(pid); if (neworderid == null) { neworderid = String.valueOf(pmodel.getOrderid()) + "01"; } else { int newOrderid = Integer.valueOf(neworderid) + 1; neworderid = String.valueOf(newOrderid); } model.setOrderid(Integer.valueOf(neworderid)); resCatalogService.updateByPrimaryKeySelective(model); int childCount = resCatalogService.selectResCatalogIsExistsSon(model.getCatlogid(),null); if (childCount > 0) { updateChildrenOid(model.getCatlogid()); } } } /** * @Description: 资源排序页面 */ @ResponseBody @RequiresPermissions("res:catalog:edit") @RequestMapping("manage/catalog/initzysort") public String initZySort(Integer id) { List List = resMainInfoService.selectZyByMuLuId(id); String Result = "{count:" + List.size() + ", children:["; for (Res_MainInfo model : List) { Result = Result + "{id:" + model.getResourceid() + ", name:'" + model.getTitle() + "'},"; } if (List.size() != 0) { Result = Result.substring(0, Result.length() - 1); } Result = Result + "]}"; return Result; } /** * @Description: 资源上移方法 */ public int zyUpSort(int id, int pid) { List List = resMainInfoService.selectZyByMuLuId(pid); int index = -1; for (Res_MainInfo model : List) { if (model.getResourceid() == id) { if (index == -1) { return 0; } else { int newoid = List.get(index).getOrderid(); List.get(index).setOrderid(model.getOrderid()); model.setOrderid(newoid); resMainInfoService.updateByPrimaryKeySelective(model); resMainInfoService.updateByPrimaryKeySelective(List.get(index)); } } index++; } return 1; } /** * @Description: 资源下移方法 */ public int zyDownSort(int id, int pid) { List List = resMainInfoService.selectZyByMuLuId(pid); int index = 1; for (Res_MainInfo model : List) { if (model.getResourceid() == id) { if (index >= List.size()) { return 0; } else { int newoid = List.get(index).getOrderid(); List.get(index).setOrderid(model.getOrderid()); model.setOrderid(newoid); resMainInfoService.updateByPrimaryKeySelective(model); resMainInfoService.updateByPrimaryKeySelective(List.get(index)); } } index++; } return 1; } }