package com.landtool.lanbase.modules.res.controller; import java.net.URLDecoder; import java.sql.Timestamp; import java.text.SimpleDateFormat; import java.util.Date; import java.util.HashMap; import java.util.LinkedHashMap; import java.util.LinkedList; import java.util.List; import java.util.Map; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Controller; import org.springframework.ui.Model; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.ResponseBody; import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.serializer.SerializerFeature; import com.github.pagehelper.Page; import com.github.pagehelper.PageHelper; import com.landtool.lanbase.common.annotation.LogAction; import com.landtool.lanbase.common.utils.Result; import com.landtool.lanbase.config.SysTemPropertyConfig; import com.landtool.lanbase.modules.api.utils.PageBean; import com.landtool.lanbase.modules.org.entity.OrgUser; import com.landtool.lanbase.modules.org.service.OrgUnitService; import com.landtool.lanbase.modules.org.service.OrgUserService; 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_Theme; import com.landtool.lanbase.modules.res.entity.Res_Theme_Module; import com.landtool.lanbase.modules.res.entity.Res_Theme_Relation; import com.landtool.lanbase.modules.res.service.ResMainInfoService; import com.landtool.lanbase.modules.res.service.ResThemeModuleService; import com.landtool.lanbase.modules.res.service.ResThemeRelationService; import com.landtool.lanbase.modules.res.service.ResThemeService; import com.landtool.lanbase.modules.sys.controller.AbstractController; import com.landtool.lanbase.modules.sys.service.SysFieldvalueService; @Controller @RequestMapping("/res/ResTheme") public class ResThemeController extends AbstractController { @Autowired private ResThemeService resThemeService; @Autowired public SysTemPropertyConfig sysConfig; @Autowired private ResThemeRelationService resThemeRelationService; @Autowired private ResThemeModuleService resThemeModuleService; @Autowired private OrgUserService orgUserService; @Autowired private ResMainInfoService resMainInfoService; @Autowired private SysFieldvalueService FieldUtils; @Autowired private OrgUnitService orgUnitService; /** * 访问业务专题 * @param model * @return */ @RequestMapping("index") public String resThemeIndex(Model model) { model.addAttribute("pubzyWebRoot", sysConfig.getPubzyWebRoot()); model.addAttribute("systemName", sysConfig.getAppFullName()); return "/ResManage/ResTheme/index"; } /** * 查询业务专题列表 * @param resTheme * @param pageBean * @return */ @ResponseBody @RequestMapping("selectResTheme") @LogAction("资源管理,业务专题,业务专题列表查询,查询") public Result selectResTheme(Res_Theme resTheme, PageBean pageBean) { PageHelper.startPage(pageBean.getPage(), pageBean.getLimit()); List list = resThemeService.selectResTheme(resTheme); SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd"); int countNums = (int) ((Page) list).getTotal(); PageBean pageData = new PageBean<>(pageBean.getPage(), pageBean.getLimit(), countNums); pageData.setItems(list); List> maps = new LinkedList<>(); for (int i = 0; i < list.size(); i++) { String name = ""; String title = list.get(i).getTitle(); if (list.get(i).getAdduserid() != null) { name = orgUserService.getChinesename(list.get(i).getAdduserid()); } Map map = new HashMap<>(); map.put("themeid",list.get(i).getThemeid()); map.put("title",title); map.put("addtime",sdf.format(list.get(i).getAddtime())); map.put("isdefault",list.get(i).getIsdefault()); map.put("isonemap",list.get(i).getIsonemap()); map.put("adduserid",name); maps.add(map); } return Result.ok().put("topics",maps).put("totalCount",countNums); } /** * 新增业务专题 * @param themeid * @return */ @RequestMapping("addResTheme") public String AddResTheme(Integer themeid, Model model) { Res_Theme resTheme = new Res_Theme(); SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd"); Res_Theme_Module resThemeModule = new Res_Theme_Module(); String name = null; LinkedHashMap moduleList = new LinkedHashMap(); if (themeid != null) { resTheme = resThemeService.selectByThemeId(themeid); List list = resThemeRelationService.selectByIdList(themeid); if (list.size() != 0) { for (int i = 0; i < list.size(); i++) { resThemeModule = resThemeModuleService.selectByid(list.get(i).getModuleid()); moduleList.put(resThemeModule.getTitle(),resThemeModule.getModuleid()); } } if (resTheme.getAdduserid() != null) { name = orgUserService.getChinesename(resTheme.getAdduserid()); } model.addAttribute("addtime", sdf.format(resTheme.getAddtime())); model.addAttribute("adduserName", name); if(resTheme.getResourceid() != null) { Res_MainInfo res_mainInfo = resMainInfoService.selectByPrimaryKey(resTheme.getResourceid()); if(res_mainInfo != null) { resTheme.setThememap(res_mainInfo.getTitle()); } } } if (themeid == null) { //获取当前登录人id name 还有对应的单位id name model.addAttribute("adduserName", getLoginName()); model.addAttribute("addtime", sdf.format(new Date())); } model.addAttribute("moduleList", moduleList); model.addAttribute("resTheme", resTheme); model.addAttribute("themeid", themeid); model.addAttribute("resThemeModule", resThemeModule); model.addAttribute("pubzyWebRoot", sysConfig.getPubzyWebRoot()); model.addAttribute("systemName", sysConfig.getAppFullName()); model.addAttribute("content", resTheme.getContent()); model.addAttribute("jspwebroot", sysConfig.getPubzyWebRoot().replace("javapubzy/", ""));// 临时处理 return "/ResManage/ResTheme/AddResTheme"; } @ResponseBody @RequestMapping("insert") public int insert(Res_Theme record) { return resThemeService.insert(record); } /** * 新增修改方法 * @param record * @param moduleid * @return */ @ResponseBody @RequestMapping("insertSelective") public String insertSelective(Res_Theme record, String moduleid) { String msg = ""; if (record.getThemeid() == null) { if (record.getIsdefault() == null) { record.setIsdefault((byte) 0); //设置默认专题为0 } if (record.getIsonemap() == null) { record.setIsonemap((byte) 0); //设置是否一张图为0 } record.setOrderindex(0); //设置排序号为0 record.setAdduserid(getUserId().intValue()); Timestamp audittime = new Timestamp(new Date().getTime());//获取当前时间 record.setAddtime(audittime); int r = resThemeService.insertSelective(record); int t = 1; if (moduleid != null && !moduleid.isEmpty()) { Res_Theme_Relation resThemeRelation = new Res_Theme_Relation(); String[] mid = moduleid.split(","); for (int i = 0; i < mid.length; i++) { resThemeRelation.setModuleid(Integer.valueOf(mid[i])); resThemeRelation.setThemeid(record.getThemeid()); t = resThemeRelationService.insert(resThemeRelation); } } System.out.println(record.toString()); if (r > 0 && t == 1) { msg = "保存成功!"; } else { msg = "保存失败!"; } } else { if (record.getIsdefault() == null) { record.setIsdefault((byte) 0); //设置默认专题为0 } if (record.getIsonemap() == null) { record.setIsonemap((byte) 0); //设置是否一张图为0 } int r = resThemeService.updateById(record); int t = 1; resThemeRelationService.deleteByThemeId(record.getThemeid()); if (moduleid != null && !moduleid.isEmpty()) { Res_Theme_Relation resThemeRelation = new Res_Theme_Relation(); resThemeRelationService.deleteByThemeId(record.getThemeid()); String[] mid = moduleid.split(","); for (int i = 0; i < mid.length; i++) { resThemeRelation.setModuleid(Integer.valueOf(mid[i])); resThemeRelation.setThemeid(record.getThemeid()); t = resThemeRelationService.insert(resThemeRelation); } } if (r > 0 && t == 1) { msg = "更新成功!"; } else { msg = "更新失败!"; } } return "{'msg':'" + msg + "','id':'" + record.getThemeid() + "'}"; } @ResponseBody @RequestMapping("UpModuleid") public String UpModuleid(String moduleid,Integer Themeid){ int t=1; if (moduleid != null && !moduleid.isEmpty()) { Res_Theme_Relation resThemeRelation = new Res_Theme_Relation(); resThemeRelationService.deleteByThemeId(Themeid); String[] mid = moduleid.split(","); for (int i = 0; i < mid.length; i++) { resThemeRelation.setModuleid(Integer.valueOf(mid[i])); resThemeRelation.setThemeid(Themeid); resThemeRelation.setOrderid(i); t = resThemeRelationService.insert(resThemeRelation); } } String msg=""; if (t == 1) { msg = "更新成功!"; } else { msg = "更新失败!"; } return "{'msg':'" + msg + "'}"; } @ResponseBody @RequestMapping("deleteById") @LogAction("资源管理,业务专题,业务专题删除,删除") public int DeleteById(Integer themeid) { List list = resThemeRelationService.selectByIdList(themeid); int t = 1; if (list.size() > 0) { t = resThemeRelationService.deleteByThemeId(themeid); //删除业务专题前把关联的信息删除 } int r = resThemeService.deleteById(themeid); if (t > 0 && r == 1) { return 1; } else { return 0; } } @RequestMapping("ZhuanTiDiTu") public String ZhuanTiDiTu(Model model) { model.addAttribute("pubzyWebRoot", sysConfig.getPubzyWebRoot()); model.addAttribute("systemName", sysConfig.getAppFullName()); return "/ResManage/ResTheme/ZhuangTiDiTuTree"; } /** * @Description: 查询有权限的专题地图 * @author ykm * @return * @date 2018/8/10 15:38 */ @RequestMapping("selectThemeMapTree") @ResponseBody public String selectThemeMapTree(Res_MainInfo resMainInfo,String parentid) { StringBuilder sb = new StringBuilder(); Map map = new HashMap<>(); OrgUser user = getUser(); map.put("userid", user.getUserid()); map.put("unitid", orgUserService.getDefaultUnit(user.getUserid()).getUnitid()); map.put("title", resMainInfo.getTitle()); map.put("parentid", parentid); List resCatalogs = resThemeService.selectThememapNode(map); //修改因英文单引号 '和双引号" 导致的错误 alert ykm 2019/01/08 List> maps = new LinkedList<>(); // 循环构造子目录节点 for (Res_Catalog resCatalog : resCatalogs) { Map nodemap = new HashMap<>(); nodemap.put("resourceid", resMainInfo.getResourceid()); nodemap.put("userid", user.getUserid()); nodemap.put("unitid", orgUserService.getDefaultUnit(user.getUserid()).getUnitid()); nodemap.put("title", resMainInfo.getTitle()); nodemap.put("datasources", resMainInfo.getDatasources()); nodemap.put("selectids", resMainInfo.getSelectids()); nodemap.put("parentid", resCatalog.getCatlogid()); int childCount = resThemeService.selectThemeMapTree(nodemap).size(); Map remap = new HashMap<>(); if(childCount > 0) { remap.put("id",resCatalog.getCatlogid()); remap.put("name",resCatalog.getTitle()); remap.put("title",resCatalog.getTitle()); remap.put("isParent",true); remap.put("iconOpen","/image/classicons/folderOpen.png',iconClose:'/image/classicons/folderOpen.png"); remap.put("iconClose","/image/classicons/folderOpen.png',iconClose:'/image/classicons/folder.png"); maps.add(remap); } else { if(!getTreeNode(nodemap).isEmpty()) { remap.put("id",resCatalog.getCatlogid()); remap.put("name",resCatalog.getTitle()); remap.put("title",resCatalog.getTitle()); remap.put("isParent",true); remap.put("iconOpen","/image/classicons/folderOpen.png',iconClose:'/image/classicons/folderOpen.png"); remap.put("iconClose","/image/classicons/folderOpen.png',iconClose:'/image/classicons/folder.png"); maps.add(remap); } } } List list = resThemeService.selectThemeMapTree(map); HashMap DataSourceList = FieldUtils.getDataSourceList();// 获取数据来源列表 // 循环构造资源节点 for (Res_MainInfo resMainInfo1 : list) { Map remap = new HashMap<>(); remap.put("id","ZiYuan_" + resMainInfo1.getResourceid()); remap.put("name",resMainInfo1.getTitle()); remap.put("title",resMainInfo1.getDatasources()); remap.put("isParent",false); remap.put("icon","/image/classicons/"+resMainInfo1.getResourceclass()+".png"); maps.add(remap); } return JSON.toJSONString(maps, SerializerFeature.WriteMapNullValue); } public String getTreeNode(Map map) { StringBuilder sb = new StringBuilder(); List resCatalogs = resThemeService.selectThememapNode(map); // 循环构造子目录节点 for (Res_Catalog resCatalog : resCatalogs) { Map nodemap = new HashMap<>(); nodemap = map; nodemap.put("parentid", resCatalog.getCatlogid()); int childCount = resThemeService.selectThemeMapTree(nodemap).size(); if(childCount > 0) { if (!"".equals(sb.toString())) { sb.append(','); } sb.append("{id: " + resCatalog.getCatlogid() + ",name:'" + resCatalog.getTitle() + "',title:'" + resCatalog.getTitle() + "',isParent: true}"); } else { if(!getTreeNode(nodemap).isEmpty()) { if (!"".equals(sb.toString())) { sb.append(','); } sb.append("{id: " + resCatalog.getCatlogid() + ",name:'" + resCatalog.getTitle() + "',title:'" + resCatalog.getTitle() + "',isParent: true,icon:'/image/classicons/defaulticon.png'}");//update:dsh(2018/12/05) sb.append(getTreeNode(nodemap)); } } } System.out.println(sb.toString()); return sb.toString(); } /** * 自动补全输入首字母查询 * @param keyWord * @return */ @ResponseBody @GetMapping("/findPinyinByKeyWord") public String[] findpinyinByKeyWord(@RequestParam(name = "keyWord") String keyWord){ keyWord = URLDecoder.decode(keyWord); Map map = new HashMap(); OrgUser user = getUser(); map.put("userid", user.getUserid()); map.put("unitid", orgUserService.getDefaultUnit(user.getUserid()).getUnitid()); map.put("keyWord",keyWord); List list = null; list = resThemeService.selectThemeMapTree(map); String[] arr = new String[list.size()]; for (int i =0;i list = resThemeService.selectResTheme(new Res_Theme()); // rsb.append("["); List> maps = new LinkedList<>(); for (int i = 0; i < list.size(); i++) { String name = ""; // if (i != 0) { // rsb.append(","); // } // rsb.append("{'themeid':'" + list.get(i).getThemeid() + "'"); // rsb.append(",'title':'" + list.get(i).getTitle() + "'}"); Map map = new HashMap<>(); map.put("themeid",list.get(i).getThemeid()); map.put("title",list.get(i).getTitle()); maps.add(map); } // rsb.append("]"); return Result.ok().put("result",maps); } /** * 更改排序 * @return */ @ResponseBody @RequestMapping("updateOrderid") public String updateOrderid(String ids) { Integer result = 0; String[] idList = ids.split(","); for(int i = 0;i map = new HashMap<>(); OrgUser user = getUser(); map.put("parentid", parentid); map.put("resourceclass", resourceclass); map.put("userid", user.getUserid()); map.put("unitid", orgUserService.getDefaultUnit(user.getUserid()).getUnitid()); map.put("catlogid", catlogid); List resCatalogList = resThemeService.selectKongJianFuWuNode(map);// 获取子目录列表 // 循环构造子目录节点 List> maps = new LinkedList<>(); for (Res_Catalog resCatalog : resCatalogList) { Map catlogmap = new HashMap<>(); catlogmap.put("id", resCatalog.getCatlogid()); catlogmap.put("name", resCatalog.getTitle()); catlogmap.put("title", resCatalog.getTitle()); catlogmap.put("isParent", true); catlogmap.put("iconOpen", "/image/classicons/folderOpen.png"); catlogmap.put("iconClose", "/image/classicons/folder.png"); maps.add(catlogmap); // if (!"".equals(resCatalogJson.toString())) { // resCatalogJson.append(','); // } // resCatalogJson.append("{id: " + resCatalog.getCatlogid() + ",name:'" + resCatalog.getTitle()+"',title:'" + resCatalog.getTitle() +"',isParent: true"+",iconOpen:'/image/classicons/folderOpen.png',iconClose:'/image/classicons/folder.png'"+"}"); } // 获取资源类型列表 List resMainInfos = resThemeService.selectKongJianFuWuTree(map); // 获取目录下业务图层资源列表 // 循环构造资源节点 for (Res_MainInfo resMainInfo1 : resMainInfos) { String unitname = orgUnitService.getUnitName((long) resMainInfo1.getPubunitid()); Map catlogmap = new HashMap<>(); catlogmap.put("id", "ZiYuan_" + resMainInfo1.getResourceid()); catlogmap.put("name", resMainInfo1.getTitle() + (unitname != null && unitname.length() > 0 ? ("(" + unitname + ")") : "")); catlogmap.put("title", resMainInfo1.getTitle()); catlogmap.put("isParent", false); catlogmap.put("icon", "/image/classicons/" + resMainInfo1.getResourceclass() + ".png"); maps.add(catlogmap); // if (!"".equals(resCatalogJson.toString())) { // resCatalogJson.append(','); // } // // resCatalogJson.append("{id: 'ZiYuan_" + resMainInfo1.getResourceid() + "',name:'" + resMainInfo1.getTitle() // + (unitname != null && unitname.length() > 0 ? ("(" + unitname + ")") : "") + "', title: '" // + resMainInfo1.getDatasources() + "',isParent:false,icon:'/image/classicons/" + resMainInfo1.getResourceclass() + ".png'}");//update:dsh(2018/12/05) } return JSON.toJSONString(maps, SerializerFeature.WriteMapNullValue); } }