package com.landtool.lanbase.modules.res.controller; 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.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.ResponseBody; import com.github.pagehelper.Page; import com.github.pagehelper.PageHelper; import com.landtool.lanbase.common.utils.Result; import com.landtool.lanbase.modules.api.utils.PageBean; import com.landtool.lanbase.modules.res.entity.Res_QueryAround; import com.landtool.lanbase.modules.res.service.ResQueryAroundService; import com.landtool.lanbase.modules.sys.service.SysFieldvalueService; @Controller @RequestMapping("res/queryaround") public class ResQueryAroundController { @Autowired private ResQueryAroundService resQueryAroundService; @Autowired private SysFieldvalueService FieldUtils; /** * 获取资源设置列表 */ @ResponseBody @RequestMapping("/getResourceSetZBCX") public Result getResourceSetZBCX(Integer resourceid, PageBean pageBean) { Page page = PageHelper.startPage(pageBean.getPage(), pageBean.getLimit()); List list = resQueryAroundService.getResourceSetZBCX(resourceid); int countNums = (int) ((Page) list).getTotal(); PageBean pageData = new PageBean<>(pageBean.getPage(), pageBean.getLimit(), countNums); pageData.setItems(list); //资源类型 LinkedHashMap resourceTypeList = FieldUtils.getFieldListByKey("ResourceType");//获取资源类型列表 // 拼接字符串 StringBuilder rsb = new StringBuilder(); rsb.append("{'totalCount':'" + countNums); rsb.append("','topics':["); List> maps = new LinkedList<>(); for (Integer i = 0; i < list.size(); i++) { Map map = new HashMap<>(); map.put("TITLE", list.get(i).getTitle()); map.put("resourceclass", resourceTypeList.get(list.get(i).getResourceclass())); map.put("DATASOURCES", (list.get(i).getDatasources() != null ?list.get(i).getDatasources():"")); map.put("CREATDATE", ""); map.put("AROUNDRESID", list.get(i).getAroundresid()); map.put("QUERYID", list.get(i).getQueryid()); maps.add(map); } return Result.ok().put("totalCount", countNums).put("topics", maps); } /** * 新增记录 */ @ResponseBody @RequestMapping("/insert") public String insert(Res_QueryAround res_queryAround, String ZiYuanIdStr) { res_queryAround.setAdduserid(0); String[] arr = ZiYuanIdStr.split("\\|"); try { for (int i = 0; i < arr.length; i++) { String s = arr[i]; res_queryAround.setAroundresid(Integer.valueOf(s)); resQueryAroundService.insert(res_queryAround); } return "1"; // 添加成功 } catch (Exception e) { return e.toString(); } } /** * 删除记录 */ @ResponseBody @RequestMapping("/deleteByPrimaryKey") public String deleteByPrimaryKey(Res_QueryAround res_queryAround) { try { int result = resQueryAroundService.deleteByPrimaryKey(res_queryAround.getQueryid()); return String.valueOf(result); } catch (Exception e) { return e.toString(); } } }