package com.landtool.lanbase.modules.res.controller; import java.util.HashMap; 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.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.config.SysTemPropertyConfig; import com.landtool.lanbase.modules.api.utils.PageBean; import com.landtool.lanbase.modules.res.entity.Res_EchartsConfing; import com.landtool.lanbase.modules.res.service.ResEchartsCofingService; @Controller @RequestMapping("res/common") public class ResEchartsCofingController { @Autowired private ResEchartsCofingService resEchartsCofingService; @Autowired private SysTemPropertyConfig sysConfig; /** * Echarts模板 */ @RequestMapping("chartTemplat") public String chartTemplat(Model model) { model.addAttribute("pubzyWebRoot", sysConfig.getPubzyWebRoot()); return "common/resource_set_ChartTemplat"; } @RequestMapping("addChartTemplat") public String addChartTemplat(Model model, Integer echartsid) { model.addAttribute("pubzyWebRoot", sysConfig.getPubzyWebRoot()); model.addAttribute("uploadRootPath", sysConfig.getUploadRootPath()); Res_EchartsConfing resEchartsConfing = new Res_EchartsConfing(); if (echartsid != null) { resEchartsConfing = resEchartsCofingService.selectByPrimaryKey(echartsid); } model.addAttribute("EchartsConfing", resEchartsConfing); return "common/resource_add_ChartTemplat"; } @RequestMapping("getChartTemplatList") @ResponseBody public Result getChartTemplatList(PageBean pageBean,Integer settype) { Page page = PageHelper.startPage(pageBean.getPage(), pageBean.getLimit()); List list = resEchartsCofingService.selectAllChart(settype); int countNums = (int) ((Page) list).getTotal(); PageBean pageData = new PageBean<>(pageBean.getPage(), pageBean.getLimit(), countNums); pageData.setItems(list); StringBuilder sb = new StringBuilder(); sb.append("{'totalCount':'" + countNums + "'"); sb.append(",'topics':["); List> maps = new LinkedList<>(); for (int i = 0; i < list.size(); i++) { Map map = new HashMap<>(); map.put("echartstype", list.get(i).getEchartstype()); map.put("echartsid", list.get(i).getEchartsid()); map.put("echartstitle", list.get(i).getEchartstitle()); map.put("echartsUrl", sysConfig.getUploadRootPath() + list.get(i).getEchartsUrl()); maps.add(map); // if (i != 0) { // sb.append(","); // } // sb.append("{"); // sb.append("'echartstype':'" + list.get(i).getEchartstype() + "'"); // sb.append(",'echartsid':'" + list.get(i).getEchartsid() + "'"); // sb.append(",'echartstitle':'" + list.get(i).getEchartstitle() + "'"); // sb.append(",'echartsUrl':'" +sysConfig.getUploadRootPath() + list.get(i).getEchartsUrl() + "'"); // sb.append("}"); } // sb.append("]}"); return Result.ok().put("totalCount", countNums).put("topics", maps); } @ResponseBody @RequestMapping("saveChartTemplat") public String saveChartTemplat(Res_EchartsConfing resEchartsConfing) { Res_EchartsConfing res_echartsConfing = resEchartsCofingService.selectByPrimaryKey(resEchartsConfing.getEchartsid()); int count = 0; if (res_echartsConfing == null) { count = resEchartsCofingService.insertSelective(resEchartsConfing); } else { count = resEchartsCofingService.updateByPrimaryKeySelective(resEchartsConfing); } return "{'count':'" + count + "','id':'"+resEchartsConfing.getEchartsid()+"'}"; } @ResponseBody @RequestMapping("deleteChartTemplat") public int deleteChartTemplat(Integer echartsid) { return resEchartsCofingService.deleteByPrimaryKey(echartsid); } }