diff --git a/contact-center/app/src/main/java/com/chatopera/cc/config/AppCtxRefreshEventListener.java b/contact-center/app/src/main/java/com/chatopera/cc/config/AppCtxRefreshEventListener.java index b0761e63..5056ab9c 100644 --- a/contact-center/app/src/main/java/com/chatopera/cc/config/AppCtxRefreshEventListener.java +++ b/contact-center/app/src/main/java/com/chatopera/cc/config/AppCtxRefreshEventListener.java @@ -1,136 +1,136 @@ -/* - * Copyright (C) 2017 优客服-多渠道客服系统 - * Modifications copyright (C) 2018-2019 Chatopera Inc, - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.chatopera.cc.config; - -import com.chatopera.cc.basic.Constants; -import com.chatopera.cc.basic.MainContext; -import com.chatopera.cc.basic.MainUtils; -import com.chatopera.cc.cache.Cache; -import com.chatopera.cc.model.BlackEntity; -import com.chatopera.cc.model.SysDic; -import com.chatopera.cc.model.SystemConfig; -import com.chatopera.cc.persistence.repository.BlackListRepository; -import com.chatopera.cc.persistence.repository.SysDicRepository; -import com.chatopera.cc.persistence.repository.SystemConfigRepository; -import com.chatopera.cc.persistence.repository.TablePropertiesRepository; -import org.apache.commons.lang3.StringUtils; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.springframework.context.ApplicationListener; -import org.springframework.context.event.ContextRefreshedEvent; - -import java.util.*; - -public class AppCtxRefreshEventListener implements ApplicationListener { - - private static final Logger logger = LoggerFactory.getLogger(AppCtxRefreshEventListener.class); - - @Override - public void onApplicationEvent(ContextRefreshedEvent event) { - if (MainContext.getContext() == null) { - logger.info("[onApplicationEvent] set main context and initialize the Cache System."); - MainContext.setApplicationContext(event.getApplicationContext()); - SysDicRepository sysDicRes = event.getApplicationContext().getBean(SysDicRepository.class); - BlackListRepository blackListRes = event.getApplicationContext().getBean(BlackListRepository.class); - Cache cache = event.getApplicationContext().getBean(Cache.class); - String cacheSetupStrategy = event.getApplicationContext().getEnvironment().getProperty("cache.setup.strategy"); - - - if (!StringUtils.equalsIgnoreCase(cacheSetupStrategy, Constants.cache_setup_strategy_skip)) { - - /************************** - * 加载系统到缓存 - * 加载系统词典大约只需要5s左右 - **************************/ - - // 首先将之前缓存清空,此处使用系统的默认租户信息 - cache.eraseSysDicByOrgi(MainContext.SYSTEM_ORGI); - - List sysDicList = sysDicRes.findAll(); - Map> rootDictItems = new HashMap<>(); // 关联根词典及其子项 - Map rootDics = new HashMap<>(); - Set parents = new HashSet<>(); - - // 获得所有根词典 - for (final SysDic dic : sysDicList) { - if (StringUtils.equals(dic.getParentid(), "0")) { - parents.add(dic.getId()); - rootDics.put(dic.getId(), dic); - } - } - - // 向根词典中添加子项 - for (final SysDic dic : sysDicList) { - if ((!StringUtils.equals(dic.getParentid(), "0")) && - parents.contains(dic.getDicid())) { - // 不是根词典,并且包含在一个根词典内 - if (!rootDictItems.containsKey(dic.getDicid())) { - rootDictItems.put(dic.getDicid(), new ArrayList()); - } - rootDictItems.get(dic.getDicid()).add(dic); - } - } - - // 更新缓存 - // TODO 集群时注意!!! - // 此处为长时间的操作,如果在一个集群中,会操作共享内容,非常不可靠 - // 所以,当前代码不支持集群,需要解决启动上的这个问题! - - // 存储根词典 TODO 此处只考虑了系统默认租户 - cache.putSysDicByOrgi(new ArrayList<>(rootDics.values()), MainContext.SYSTEM_ORGI); - - for (final Map.Entry> entry : rootDictItems.entrySet()) { - SysDic rootDic = rootDics.get(entry.getKey()); - // 打印根词典信息 - logger.debug("[onApplicationEvent] root dict: {}, code {}, name {}, item size {}", entry.getKey(), rootDics.get(entry.getKey()).getCode(), rootDics.get(entry.getKey()).getName(), entry.getValue().size()); - // 存储子项列表 - cache.putSysDicByOrgi(rootDic.getCode(), MainContext.SYSTEM_ORGI, entry.getValue()); - // 存储子项成员 - cache.putSysDicByOrgi(entry.getValue(), MainContext.SYSTEM_ORGI); - } - - List blackList = blackListRes.findByOrgi(MainContext.SYSTEM_ORGI); - for (final BlackEntity black : blackList) { - if (StringUtils.isNotBlank(black.getUserid())) { - if (black.getEndtime() == null || black.getEndtime().after(new Date())) { - cache.putSystemByIdAndOrgi(black.getUserid(), black.getOrgi(), black); - } - } - } - - /** - * 加载系统全局配置 - */ - SystemConfigRepository systemConfigRes = event.getApplicationContext().getBean(SystemConfigRepository.class); - SystemConfig config = systemConfigRes.findByOrgi(MainContext.SYSTEM_ORGI); - if (config != null) { - cache.putSystemByIdAndOrgi("systemConfig", MainContext.SYSTEM_ORGI, config); - } - logger.info("[StartedEventListener] setup Sysdicts in Redis done, strategy {}", cacheSetupStrategy); - } else { - logger.info("[onApplicationEvent] skip initialize sysdicts."); - } - - MainUtils.initSystemArea(); - - MainUtils.initSystemSecField(event.getApplicationContext().getBean(TablePropertiesRepository.class)); - // MainUtils.initAdv();//初始化广告位 - } else { - logger.info("[onApplicationEvent] bypass, initialization has been done already."); - } - } -} \ No newline at end of file +/* + * Copyright (C) 2017 优客服-多渠道客服系统 + * Modifications copyright (C) 2018-2019 Chatopera Inc, + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.chatopera.cc.config; + +import com.chatopera.cc.basic.Constants; +import com.chatopera.cc.basic.MainContext; +import com.chatopera.cc.basic.MainUtils; +import com.chatopera.cc.cache.Cache; +import com.chatopera.cc.model.BlackEntity; +import com.chatopera.cc.model.SysDic; +import com.chatopera.cc.model.SystemConfig; +import com.chatopera.cc.persistence.repository.BlackListRepository; +import com.chatopera.cc.persistence.repository.SysDicRepository; +import com.chatopera.cc.persistence.repository.SystemConfigRepository; +import com.chatopera.cc.persistence.repository.TablePropertiesRepository; +import org.apache.commons.lang3.StringUtils; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.context.ApplicationListener; +import org.springframework.context.event.ContextRefreshedEvent; + +import java.util.*; + +public class AppCtxRefreshEventListener implements ApplicationListener { + + private static final Logger logger = LoggerFactory.getLogger(AppCtxRefreshEventListener.class); + + @Override + public void onApplicationEvent(ContextRefreshedEvent event) { + if (MainContext.getContext() == null) { + logger.info("[onApplicationEvent] set main context and initialize the Cache System."); + MainContext.setApplicationContext(event.getApplicationContext()); + SysDicRepository sysDicRes = event.getApplicationContext().getBean(SysDicRepository.class); + BlackListRepository blackListRes = event.getApplicationContext().getBean(BlackListRepository.class); + Cache cache = event.getApplicationContext().getBean(Cache.class); + String cacheSetupStrategy = event.getApplicationContext().getEnvironment().getProperty("cache.setup.strategy"); + + + if (!StringUtils.equalsIgnoreCase(cacheSetupStrategy, Constants.cache_setup_strategy_skip)) { + + /************************** + * 加载系统到缓存 + * 加载系统词典大约只需要5s左右 + **************************/ + + // 首先将之前缓存清空,此处使用系统的默认租户信息 + cache.eraseSysDicByOrgi(MainContext.SYSTEM_ORGI); + + List sysDicList = sysDicRes.findAll(); + Map> rootDictItems = new HashMap<>(); // 关联根词典及其子项 + Map rootDics = new HashMap<>(); + Set parents = new HashSet<>(); + + // 获得所有根词典 + for (final SysDic dic : sysDicList) { + if (StringUtils.equals(dic.getParentid(), "0")) { + parents.add(dic.getId()); + rootDics.put(dic.getId(), dic); + } + } + + // 向根词典中添加子项 + for (final SysDic dic : sysDicList) { + if ((!StringUtils.equals(dic.getParentid(), "0")) && + parents.contains(dic.getDicid())) { + // 不是根词典,并且包含在一个根词典内 + if (!rootDictItems.containsKey(dic.getDicid())) { + rootDictItems.put(dic.getDicid(), new ArrayList()); + } + rootDictItems.get(dic.getDicid()).add(dic); + } + } + + // 更新缓存 + // TODO 集群时注意!!! + // 此处为长时间的操作,如果在一个集群中,会操作共享内容,非常不可靠 + // 所以,当前代码不支持集群,需要解决启动上的这个问题! + + // 存储根词典 TODO 此处只考虑了系统默认租户 + cache.putSysDicByOrgi(new ArrayList<>(rootDics.values()), MainContext.SYSTEM_ORGI); + + for (final Map.Entry> entry : rootDictItems.entrySet()) { + SysDic rootDic = rootDics.get(entry.getKey()); + // 打印根词典信息 + logger.debug("[onApplicationEvent] root dict: {}, code {}, name {}, item size {}", entry.getKey(), rootDics.get(entry.getKey()).getCode(), rootDics.get(entry.getKey()).getName(), entry.getValue().size()); + // 存储子项列表 + cache.putSysDicByOrgi(rootDic.getCode(), MainContext.SYSTEM_ORGI, entry.getValue()); + // 存储子项成员 + cache.putSysDicByOrgi(entry.getValue(), MainContext.SYSTEM_ORGI); + } + + List blackList = blackListRes.findByOrgi(MainContext.SYSTEM_ORGI); + for (final BlackEntity black : blackList) { + if (StringUtils.isNotBlank(black.getUserid())) { + if (black.getEndtime() == null || black.getEndtime().after(new Date())) { + cache.putSystemByIdAndOrgi(black.getUserid(), black.getOrgi(), black); + } + } + } + + /* + * 加载系统全局配置 + */ + SystemConfigRepository systemConfigRes = event.getApplicationContext().getBean(SystemConfigRepository.class); + SystemConfig config = systemConfigRes.findByOrgi(MainContext.SYSTEM_ORGI); + if (config != null) { + cache.putSystemByIdAndOrgi("systemConfig", MainContext.SYSTEM_ORGI, config); + } + logger.info("[StartedEventListener] setup Sysdicts in Redis done, strategy {}", cacheSetupStrategy); + } else { + logger.info("[onApplicationEvent] skip initialize sysdicts."); + } + + MainUtils.initSystemArea(); + + MainUtils.initSystemSecField(event.getApplicationContext().getBean(TablePropertiesRepository.class)); + // MainUtils.initAdv();//初始化广告位 + } else { + logger.info("[onApplicationEvent] bypass, initialization has been done already."); + } + } +} diff --git a/contact-center/app/src/main/java/com/chatopera/cc/controller/admin/system/MetadataController.java b/contact-center/app/src/main/java/com/chatopera/cc/controller/admin/system/MetadataController.java index a769c4d0..87d4b908 100644 --- a/contact-center/app/src/main/java/com/chatopera/cc/controller/admin/system/MetadataController.java +++ b/contact-center/app/src/main/java/com/chatopera/cc/controller/admin/system/MetadataController.java @@ -29,26 +29,26 @@ import com.chatopera.cc.util.Menu; import com.chatopera.cc.util.metadata.DatabaseMetaDataHandler; import com.chatopera.cc.util.metadata.UKColumnMetadata; import com.chatopera.cc.util.metadata.UKTableMetaData; +import lombok.RequiredArgsConstructor; import org.apache.commons.lang.StringUtils; import org.hibernate.Session; -import org.hibernate.jdbc.Work; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.BeansException; -import org.springframework.beans.factory.annotation.Autowired; import org.springframework.data.domain.PageRequest; import org.springframework.data.elasticsearch.repository.ElasticsearchRepository; +import org.springframework.http.HttpStatus; +import org.springframework.lang.NonNull; import org.springframework.stereotype.Controller; import org.springframework.ui.ModelMap; import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.server.ResponseStatusException; import org.springframework.web.servlet.ModelAndView; import javax.persistence.EntityManager; import javax.persistence.PersistenceContext; import javax.servlet.http.HttpServletRequest; import javax.validation.Valid; -import java.sql.Connection; -import java.sql.SQLException; import java.util.ArrayList; import java.util.Arrays; import java.util.Date; @@ -56,43 +56,39 @@ import java.util.List; @Controller @RequestMapping("/admin/metadata") +@RequiredArgsConstructor public class MetadataController extends Handler { - @Autowired - private MetadataRepository metadataRes; - - @Autowired - private BaseService service; - - @Autowired - private SysDicRepository sysDicRes; - - @Autowired - private TablePropertiesRepository tablePropertiesRes; - private static final Logger logger = LoggerFactory.getLogger(MetadataController.class); - - @Autowired + @NonNull + private final MetadataRepository metadataRes; + @NonNull + private final BaseService service; + @NonNull + private final SysDicRepository sysDicRes; + @NonNull + private final TablePropertiesRepository tablePropertiesRes; + @NonNull @PersistenceContext - private EntityManager em; + private final EntityManager em; @RequestMapping("/index") @Menu(type = "admin", subtype = "metadata", admin = true) - public ModelAndView index(ModelMap map, HttpServletRequest request) throws SQLException { + public ModelAndView index(ModelMap map, HttpServletRequest request) { map.addAttribute("metadataList", metadataRes.findAll(PageRequest.of(super.getP(request), super.getPs(request)))); return request(super.createAdminTempletResponse("/admin/system/metadata/index")); } @RequestMapping("/edit") @Menu(type = "admin", subtype = "metadata", admin = true) - public ModelAndView edit(ModelMap map, HttpServletRequest request, @Valid String id) { + public ModelAndView edit(ModelMap map, @Valid String id) { map.addAttribute("metadata", metadataRes.findById(id)); return request(super.createRequestPageTempletResponse("/admin/system/metadata/edit")); } @RequestMapping("/update") @Menu(type = "admin", subtype = "metadata", admin = true) - public ModelAndView update(ModelMap map, HttpServletRequest request, @Valid MetadataTable metadata) throws SQLException { + public ModelAndView update(@Valid MetadataTable metadata) { MetadataTable table = metadataRes.findById(metadata.getId()); table.setName(metadata.getName()); table.setFromdb(metadata.isFromdb()); @@ -104,7 +100,7 @@ public class MetadataController extends Handler { @RequestMapping("/properties/edit") @Menu(type = "admin", subtype = "metadata", admin = true) - public ModelAndView propertiesedit(ModelMap map, HttpServletRequest request, @Valid String id) { + public ModelAndView propertiesedit(ModelMap map, @Valid String id) { map.addAttribute("tp", tablePropertiesRes.findById(id)); map.addAttribute("sysdicList", sysDicRes.findByParentid("0")); map.addAttribute("dataImplList", Dict.getInstance().getDic("com.dic.data.impl")); @@ -114,8 +110,9 @@ public class MetadataController extends Handler { @RequestMapping("/properties/update") @Menu(type = "admin", subtype = "metadata", admin = true) - public ModelAndView propertiesupdate(ModelMap map, HttpServletRequest request, @Valid TableProperties tp) throws SQLException { - TableProperties tableProperties = tablePropertiesRes.findById(tp.getId()); + public ModelAndView propertiesupdate(@Valid TableProperties tp) { + TableProperties tableProperties = tablePropertiesRes.findById(tp.getId()) + .orElseThrow(() -> new ResponseStatusException(HttpStatus.NOT_FOUND, String.format("Table properties %s not found", tp.getId()))); tableProperties.setName(tp.getName()); tableProperties.setSeldata(tp.isSeldata()); tableProperties.setSeldatacode(tp.getSeldatacode()); @@ -139,7 +136,7 @@ public class MetadataController extends Handler { @RequestMapping("/delete") @Menu(type = "admin", subtype = "metadata", admin = true) - public ModelAndView delete(ModelMap map, HttpServletRequest request, @Valid String id) throws SQLException { + public ModelAndView delete(@Valid String id) { MetadataTable table = metadataRes.findById(id); metadataRes.delete(table); return request(super.createRequestPageTempletResponse("redirect:/admin/metadata/index.html")); @@ -147,33 +144,34 @@ public class MetadataController extends Handler { @RequestMapping("/batdelete") @Menu(type = "admin", subtype = "metadata", admin = true) - public ModelAndView batdelete(ModelMap map, HttpServletRequest request, @Valid String[] ids) throws SQLException { + public ModelAndView batdelete(@Valid String[] ids) { if (ids != null && ids.length > 0) { - metadataRes.delete(metadataRes.findAll(Arrays.asList(ids))); + metadataRes.deleteAll(metadataRes.findAllById(Arrays.asList(ids))); } return request(super.createRequestPageTempletResponse("redirect:/admin/metadata/index.html")); } @RequestMapping("/properties/delete") @Menu(type = "admin", subtype = "metadata", admin = true) - public ModelAndView propertiesdelete(ModelMap map, HttpServletRequest request, @Valid String id, @Valid String tbid) throws SQLException { - TableProperties prop = tablePropertiesRes.findById(id); + public ModelAndView propertiesdelete(@Valid String id, @Valid String tbid) { + TableProperties prop = tablePropertiesRes.findById(id) + .orElseThrow(() -> new ResponseStatusException(HttpStatus.NOT_FOUND, String.format("Table properties %s not found", id))); tablePropertiesRes.delete(prop); return request(super.createRequestPageTempletResponse("redirect:/admin/metadata/table.html?id=" + (!StringUtils.isBlank(tbid) ? tbid : prop.getDbtableid()))); } @RequestMapping("/properties/batdelete") @Menu(type = "admin", subtype = "metadata", admin = true) - public ModelAndView propertiesbatdelete(ModelMap map, HttpServletRequest request, @Valid String[] ids, @Valid String tbid) throws SQLException { + public ModelAndView propertiesbatdelete(@Valid String[] ids, @Valid String tbid) { if (ids != null && ids.length > 0) { - tablePropertiesRes.delete(tablePropertiesRes.findAll(Arrays.asList(ids))); + tablePropertiesRes.deleteAll(tablePropertiesRes.findAllById(Arrays.asList(ids))); } return request(super.createRequestPageTempletResponse("redirect:/admin/metadata/table.html?id=" + tbid)); } @RequestMapping("/table") @Menu(type = "admin", subtype = "metadata", admin = true) - public ModelAndView table(ModelMap map, HttpServletRequest request, @Valid String id) throws SQLException { + public ModelAndView table(ModelMap map, @Valid String id) { map.addAttribute("propertiesList", tablePropertiesRes.findByDbtableid(id)); map.addAttribute("tbid", id); map.addAttribute("table", metadataRes.findById(id)); @@ -182,17 +180,15 @@ public class MetadataController extends Handler { @RequestMapping("/imptb") @Menu(type = "admin", subtype = "metadata", admin = true) - public ModelAndView imptb(final ModelMap map, HttpServletRequest request) throws Exception { + public ModelAndView imptb(final ModelMap map) { Session session = (Session) em.getDelegate(); - session.doWork(new Work() { - public void execute(Connection connection) throws SQLException { - try { - map.addAttribute("tablesList", - DatabaseMetaDataHandler.getTables(connection)); - } catch (Exception e) { - logger.error("When import metadata", e); - } + session.doWork(connection -> { + try { + map.addAttribute("tablesList", + DatabaseMetaDataHandler.getTables(connection)); + } catch (Exception e) { + logger.error("When import metadata", e); } }); @@ -202,34 +198,32 @@ public class MetadataController extends Handler { @RequestMapping("/imptbsave") @Menu(type = "admin", subtype = "metadata", admin = true) - public ModelAndView imptb(ModelMap map, HttpServletRequest request, final @Valid String[] tables) throws Exception { + public ModelAndView imptb(HttpServletRequest request, final @Valid String[] tables) { final User user = super.getUser(request); if (tables != null && tables.length > 0) { Session session = (Session) em.getDelegate(); session.doWork( - new Work() { - public void execute(Connection connection) throws SQLException { - try { - for (String table : tables) { - int count = metadataRes.countByTablename(table); - if (count == 0) { - MetadataTable metaDataTable = new MetadataTable(); - //当前记录没有被添加过,进行正常添加 - metaDataTable.setTablename(table); - metaDataTable.setOrgi(user.getOrgi()); - metaDataTable.setId(MainUtils.md5(metaDataTable.getTablename())); - metaDataTable.setTabledirid("0"); - metaDataTable.setCreater(user.getId()); - metaDataTable.setCreatername(user.getUsername()); - metaDataTable.setName(table); - metaDataTable.setUpdatetime(new Date()); - metaDataTable.setCreatetime(new Date()); - metadataRes.save(processMetadataTable(DatabaseMetaDataHandler.getTable(connection, metaDataTable.getTablename()), metaDataTable)); - } + connection -> { + try { + for (String table : tables) { + int count = metadataRes.countByTablename(table); + if (count == 0) { + MetadataTable metaDataTable = new MetadataTable(); + //当前记录没有被添加过,进行正常添加 + metaDataTable.setTablename(table); + metaDataTable.setOrgi(user.getOrgi()); + metaDataTable.setId(MainUtils.md5(metaDataTable.getTablename())); + metaDataTable.setTabledirid("0"); + metaDataTable.setCreater(user.getId()); + metaDataTable.setCreatername(user.getUsername()); + metaDataTable.setName(table); + metaDataTable.setUpdatetime(new Date()); + metaDataTable.setCreatetime(new Date()); + metadataRes.save(processMetadataTable(DatabaseMetaDataHandler.getTable(connection, metaDataTable.getTablename()), metaDataTable)); } - } catch (Exception e) { - logger.error("When import metadata", e); } + } catch (Exception e) { + logger.error("When import metadata", e); } } ); @@ -240,7 +234,7 @@ public class MetadataController extends Handler { } private MetadataTable processMetadataTable(UKTableMetaData metaData, MetadataTable table) { - table.setTableproperty(new ArrayList()); + table.setTableproperty(new ArrayList<>()); if (metaData != null) { for (UKColumnMetadata colum : metaData.getColumnMetadatas()) { TableProperties tablePorperties = new TableProperties(colum.getName().toLowerCase(), colum.getTypeName(), colum.getColumnSize(), metaData.getName().toLowerCase()); @@ -263,7 +257,7 @@ public class MetadataController extends Handler { public String getDataTypeName(String type) { String typeName = "text"; - if (type.indexOf("varchar") >= 0) { + if (type.contains("varchar")) { typeName = "text"; } else if (type.equalsIgnoreCase("date") || type.equalsIgnoreCase("datetime")) { typeName = type.toLowerCase(); @@ -275,7 +269,7 @@ public class MetadataController extends Handler { @RequestMapping("/clean") @Menu(type = "admin", subtype = "metadata", admin = true) - public ModelAndView clean(ModelMap map, HttpServletRequest request, @Valid String id) throws SQLException, BeansException, ClassNotFoundException { + public ModelAndView clean(@Valid String id) throws BeansException, ClassNotFoundException { if (!StringUtils.isBlank(id)) { MetadataTable table = metadataRes.findById(id); if (table.isFromdb() && !StringUtils.isBlank(table.getListblocktemplet())) { @@ -295,7 +289,7 @@ public class MetadataController extends Handler { @SuppressWarnings({"rawtypes", "unchecked"}) @RequestMapping("/synctoes") @Menu(type = "admin", subtype = "metadata", admin = true) - public ModelAndView synctoes(ModelMap map, HttpServletRequest request, @Valid String id) throws SQLException, BeansException, ClassNotFoundException { + public ModelAndView synctoes(@Valid String id) throws BeansException, ClassNotFoundException { if (!StringUtils.isBlank(id)) { MetadataTable table = metadataRes.findById(id); if (table.isFromdb() && !StringUtils.isBlank(table.getListblocktemplet())) { @@ -309,9 +303,7 @@ public class MetadataController extends Handler { SysDic jpaDic = Dict.getInstance().getDicItem(table.getPreviewtemplet()); List dataList = service.list(jpaDic.getCode()); List values = new CskefuList(); - for (Object object : dataList) { - values.add(object); - } + values.addAll(dataList); if (dataList.size() > 0) { jpa.save(values); } @@ -326,7 +318,7 @@ public class MetadataController extends Handler { @SuppressWarnings({"rawtypes"}) @RequestMapping("/synctodb") @Menu(type = "admin", subtype = "metadata", admin = true) - public ModelAndView synctodb(ModelMap map, HttpServletRequest request, @Valid String id) throws SQLException, BeansException, ClassNotFoundException { + public ModelAndView synctodb(@Valid String id) throws BeansException, ClassNotFoundException { if (!StringUtils.isBlank(id)) { MetadataTable table = metadataRes.findById(id); if (table.isFromdb() && !StringUtils.isBlank(table.getListblocktemplet())) { diff --git a/contact-center/app/src/main/java/com/chatopera/cc/controller/apps/report/CubeLevelController.java b/contact-center/app/src/main/java/com/chatopera/cc/controller/apps/report/CubeLevelController.java index e1ab168b..72121dbe 100644 --- a/contact-center/app/src/main/java/com/chatopera/cc/controller/apps/report/CubeLevelController.java +++ b/contact-center/app/src/main/java/com/chatopera/cc/controller/apps/report/CubeLevelController.java @@ -1,161 +1,167 @@ -/* - * Copyright (C) 2017 优客服-多渠道客服系统 - * Modifications copyright (C) 2018-2019 Chatopera Inc, - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.chatopera.cc.controller.apps.report; - -import com.chatopera.cc.controller.Handler; -import com.chatopera.cc.model.CubeLevel; -import com.chatopera.cc.model.CubeMetadata; -import com.chatopera.cc.model.Dimension; -import com.chatopera.cc.model.TableProperties; -import com.chatopera.cc.persistence.repository.CubeLevelRepository; -import com.chatopera.cc.persistence.repository.CubeMetadataRepository; -import com.chatopera.cc.persistence.repository.DimensionRepository; -import com.chatopera.cc.persistence.repository.TablePropertiesRepository; -import com.chatopera.cc.util.Menu; -import org.apache.commons.lang.StringUtils; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.stereotype.Controller; -import org.springframework.ui.ModelMap; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.servlet.ModelAndView; - -import javax.servlet.http.HttpServletRequest; -import javax.validation.Valid; -import java.util.List; - -@Controller -@RequestMapping("/apps/report/cubelevel") -public class CubeLevelController extends Handler{ - - @Autowired - private CubeLevelRepository cubeLevelRes; - - @Autowired - private DimensionRepository dimensionRes; - - @Autowired - private TablePropertiesRepository tablePropertiesRes; - - @Autowired - private CubeMetadataRepository cubeMetadataRes; - - @RequestMapping("/add") - @Menu(type = "report" , subtype = "cubelevel") - public ModelAndView cubeLeveladd(ModelMap map , HttpServletRequest request , @Valid String cubeid,@Valid String dimid) { - map.addAttribute("cubeid", cubeid); - map.addAttribute("dimid", dimid); - //map.addAttribute("fktableList",cubeMetadataRes.findByCubeid(cubeid)); - Dimension dim = dimensionRes.findByIdAndOrgi(dimid,super.getOrgi(request)); - - if(dim!=null){ - if(!StringUtils.isBlank(dim.getFktable())) { - map.put("fktableidList", tablePropertiesRes.findByDbtableid(dim.getFktable())); - }else { - List cmList = cubeMetadataRes.findByCubeidAndMtype(cubeid,"0"); - if(!cmList.isEmpty() && cmList.get(0)!=null) { - map.put("fktableidList", tablePropertiesRes.findByDbtableid(cmList.get(0).getTb().getId())); - } - } - - } - return request(super.createRequestPageTempletResponse("/apps/business/report/cube/cubelevel/add")); - } - - @RequestMapping("/save") - @Menu(type = "report" , subtype = "cubelevel" ) - public ModelAndView cubeLevelsave(ModelMap map , HttpServletRequest request , @Valid CubeLevel cubeLevel,@Valid String tableid) { - if(!StringUtils.isBlank(cubeLevel.getName())){ - cubeLevel.setOrgi(super.getOrgi(request)); - cubeLevel.setCreater(super.getUser(request).getId()); - cubeLevel.setCode(cubeLevel.getColumname()); - if(!StringUtils.isBlank(tableid)) { - TableProperties tb = new TableProperties(); - tb.setId(tableid); - TableProperties t = tablePropertiesRes.findById(tableid); - cubeLevel.setTablename(t.getTablename()); - cubeLevel.setCode(t.getFieldname()); - cubeLevel.setColumname(t.getFieldname()); - cubeLevel.setTableproperty(tb); - } - cubeLevelRes.save(cubeLevel) ; - } - return request(super.createRequestPageTempletResponse("redirect:/apps/report/cube/detail.html?id="+cubeLevel.getCubeid()+"&dimensionId="+cubeLevel.getDimid())); - } - - @RequestMapping("/delete") - @Menu(type = "report" , subtype = "cubelevel" ) - public ModelAndView quickreplydelete(ModelMap map , HttpServletRequest request , @Valid String id) { - CubeLevel cubeLevel = cubeLevelRes.findOne(id) ; - if(cubeLevel!=null){ - cubeLevelRes.delete(cubeLevel); - } - return request(super.createRequestPageTempletResponse("redirect:/apps/report/cube/detail.html?id="+cubeLevel.getCubeid()+"&dimensionId="+cubeLevel.getDimid())); - } - @RequestMapping("/edit") - @Menu(type = "report" , subtype = "cubelevel" , admin= true) - public ModelAndView quickreplyedit(ModelMap map , HttpServletRequest request , @Valid String id) { - CubeLevel cubeLevel = cubeLevelRes.findOne(id) ; - map.put("cubeLevel", cubeLevel) ; - Dimension dim = dimensionRes.findByIdAndOrgi(cubeLevel.getDimid(),super.getOrgi(request)); - if(dim!=null){ - if(!StringUtils.isBlank(dim.getFktable())) { - map.put("fktableidList", tablePropertiesRes.findByDbtableid(dim.getFktable())); - map.addAttribute("tableid", dim.getFktable()); - }else { - List cmList = cubeMetadataRes.findByCubeidAndMtype(cubeLevel.getCubeid(),"0"); - if(!cmList.isEmpty() && cmList.get(0)!=null) { - map.put("fktableidList", tablePropertiesRes.findByDbtableid(cmList.get(0).getTb().getId())); - map.addAttribute("tableid", cmList.get(0).getId()); - } - } - - } - return request(super.createRequestPageTempletResponse("/apps/business/report/cube/cubelevel/edit")); - } - - @RequestMapping("/update") - @Menu(type = "report" , subtype = "cubelevel" , admin= true) - public ModelAndView quickreplyupdate(ModelMap map , HttpServletRequest request , @Valid CubeLevel cubeLevel,@Valid String tableid) { - if(!StringUtils.isBlank(cubeLevel.getId())){ - CubeLevel temp = cubeLevelRes.findOne(cubeLevel.getId()) ; - cubeLevel.setOrgi(super.getOrgi(request)); - cubeLevel.setCreater(super.getUser(request).getId()); - if(temp!=null){ - cubeLevel.setCreatetime(temp.getCreatetime()); - } - if(!StringUtils.isBlank(tableid)) { - TableProperties tb = new TableProperties(); - tb.setId(tableid); - TableProperties t = tablePropertiesRes.findById(tableid); - cubeLevel.setTablename(t.getTablename()); - cubeLevel.setCode(t.getFieldname()); - cubeLevel.setColumname(t.getFieldname()); - cubeLevel.setTableproperty(tb); - } - cubeLevelRes.save(cubeLevel) ; - } - return request(super.createRequestPageTempletResponse("redirect:/apps/report/cube/detail.html?id="+cubeLevel.getCubeid()+"&dimensionId="+cubeLevel.getDimid())); - } - @RequestMapping("/fktableid") - @Menu(type = "report" , subtype = "cubelevel" , admin= true) - public ModelAndView fktableid(ModelMap map , HttpServletRequest request , @Valid String tableid) { - if(!StringUtils.isBlank(tableid)){ - map.put("fktableidList", tablePropertiesRes.findByDbtableid(tableid)); - } - return request(super.createRequestPageTempletResponse("/apps/business/report/cube/cubelevel/fktableiddiv")); - } -} \ No newline at end of file +/* + * Copyright (C) 2017 优客服-多渠道客服系统 + * Modifications copyright (C) 2018-2019 Chatopera Inc, + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.chatopera.cc.controller.apps.report; + +import com.chatopera.cc.controller.Handler; +import com.chatopera.cc.model.CubeLevel; +import com.chatopera.cc.model.CubeMetadata; +import com.chatopera.cc.model.Dimension; +import com.chatopera.cc.model.TableProperties; +import com.chatopera.cc.persistence.repository.CubeLevelRepository; +import com.chatopera.cc.persistence.repository.CubeMetadataRepository; +import com.chatopera.cc.persistence.repository.DimensionRepository; +import com.chatopera.cc.persistence.repository.TablePropertiesRepository; +import com.chatopera.cc.util.Menu; +import lombok.RequiredArgsConstructor; +import org.apache.commons.lang.StringUtils; +import org.springframework.http.HttpStatus; +import org.springframework.lang.NonNull; +import org.springframework.stereotype.Controller; +import org.springframework.ui.ModelMap; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.server.ResponseStatusException; +import org.springframework.web.servlet.ModelAndView; + +import javax.servlet.http.HttpServletRequest; +import javax.validation.Valid; +import java.util.List; + +@Controller +@RequestMapping("/apps/report/cubelevel") +@RequiredArgsConstructor +public class CubeLevelController extends Handler { + + @NonNull + private final CubeLevelRepository cubeLevelRes; + + @NonNull + private final DimensionRepository dimensionRes; + + @NonNull + private final TablePropertiesRepository tablePropertiesRes; + + @NonNull + private final CubeMetadataRepository cubeMetadataRes; + + @RequestMapping("/add") + @Menu(type = "report", subtype = "cubelevel") + public ModelAndView cubeLeveladd(ModelMap map, HttpServletRequest request, @Valid String cubeid, @Valid String dimid) { + map.addAttribute("cubeid", cubeid); + map.addAttribute("dimid", dimid); + //map.addAttribute("fktableList",cubeMetadataRes.findByCubeid(cubeid)); + Dimension dim = dimensionRes.findByIdAndOrgi(dimid, super.getOrgi(request)); + + if (dim != null) { + if (!StringUtils.isBlank(dim.getFktable())) { + map.put("fktableidList", tablePropertiesRes.findByDbtableid(dim.getFktable())); + } else { + List cmList = cubeMetadataRes.findByCubeidAndMtype(cubeid, "0"); + if (!cmList.isEmpty() && cmList.get(0) != null) { + map.put("fktableidList", tablePropertiesRes.findByDbtableid(cmList.get(0).getTb().getId())); + } + } + + } + return request(super.createRequestPageTempletResponse("/apps/business/report/cube/cubelevel/add")); + } + + @RequestMapping("/save") + @Menu(type = "report", subtype = "cubelevel") + public ModelAndView cubeLevelsave(HttpServletRequest request, @Valid CubeLevel cubeLevel, @Valid String tableid) { + if (!StringUtils.isBlank(cubeLevel.getName())) { + cubeLevel.setOrgi(super.getOrgi(request)); + cubeLevel.setCreater(super.getUser(request).getId()); + cubeLevel.setCode(cubeLevel.getColumname()); + if (!StringUtils.isBlank(tableid)) { + TableProperties tb = new TableProperties(); + tb.setId(tableid); + TableProperties t = tablePropertiesRes.findById(tableid) + .orElseThrow(() -> new ResponseStatusException(HttpStatus.NOT_FOUND, String.format("Table properties %s not found", tableid))); + cubeLevel.setTablename(t.getTablename()); + cubeLevel.setCode(t.getFieldname()); + cubeLevel.setColumname(t.getFieldname()); + cubeLevel.setTableproperty(tb); + } + cubeLevelRes.save(cubeLevel); + } + return request(super.createRequestPageTempletResponse("redirect:/apps/report/cube/detail.html?id=" + cubeLevel.getCubeid() + "&dimensionId=" + cubeLevel.getDimid())); + } + + @RequestMapping("/delete") + @Menu(type = "report", subtype = "cubelevel") + public ModelAndView quickreplydelete(@Valid String id) { + CubeLevel cubeLevel = cubeLevelRes.findById(id) + .orElseThrow(() -> new ResponseStatusException(HttpStatus.NOT_FOUND, String.format("Cube level %s not found", id))); + cubeLevelRes.delete(cubeLevel); + return request(super.createRequestPageTempletResponse("redirect:/apps/report/cube/detail.html?id=" + cubeLevel.getCubeid() + "&dimensionId=" + cubeLevel.getDimid())); + } + + @RequestMapping("/edit") + @Menu(type = "report", subtype = "cubelevel", admin = true) + public ModelAndView quickreplyedit(ModelMap map, HttpServletRequest request, @Valid String id) { + CubeLevel cubeLevel = cubeLevelRes.findById(id) + .orElseThrow(() -> new ResponseStatusException(HttpStatus.NOT_FOUND, String.format("Cube level %s not found", id))); + map.put("cubeLevel", cubeLevel); + Dimension dim = dimensionRes.findByIdAndOrgi(cubeLevel.getDimid(), super.getOrgi(request)); + if (dim != null) { + if (!StringUtils.isBlank(dim.getFktable())) { + map.put("fktableidList", tablePropertiesRes.findByDbtableid(dim.getFktable())); + map.addAttribute("tableid", dim.getFktable()); + } else { + List cmList = cubeMetadataRes.findByCubeidAndMtype(cubeLevel.getCubeid(), "0"); + if (!cmList.isEmpty() && cmList.get(0) != null) { + map.put("fktableidList", tablePropertiesRes.findByDbtableid(cmList.get(0).getTb().getId())); + map.addAttribute("tableid", cmList.get(0).getId()); + } + } + + } + return request(super.createRequestPageTempletResponse("/apps/business/report/cube/cubelevel/edit")); + } + + @RequestMapping("/update") + @Menu(type = "report", subtype = "cubelevel", admin = true) + public ModelAndView quickreplyupdate(HttpServletRequest request, @Valid CubeLevel cubeLevel, @Valid String tableid) { + if (!StringUtils.isBlank(cubeLevel.getId())) { + cubeLevel.setOrgi(super.getOrgi(request)); + cubeLevel.setCreater(super.getUser(request).getId()); + cubeLevelRes.findById(cubeLevel.getId()) + .ifPresent(it -> cubeLevel.setCreatetime(it.getCreatetime())); + if (!StringUtils.isBlank(tableid)) { + TableProperties tb = new TableProperties(); + tb.setId(tableid); + TableProperties t = tablePropertiesRes.findById(tableid) + .orElseThrow(() -> new ResponseStatusException(HttpStatus.NOT_FOUND, String.format("Table properties %s not found", tableid))); + cubeLevel.setTablename(t.getTablename()); + cubeLevel.setCode(t.getFieldname()); + cubeLevel.setColumname(t.getFieldname()); + cubeLevel.setTableproperty(tb); + } + cubeLevelRes.save(cubeLevel); + } + return request(super.createRequestPageTempletResponse("redirect:/apps/report/cube/detail.html?id=" + cubeLevel.getCubeid() + "&dimensionId=" + cubeLevel.getDimid())); + } + + @RequestMapping("/fktableid") + @Menu(type = "report", subtype = "cubelevel", admin = true) + public ModelAndView fktableid(ModelMap map, @Valid String tableid) { + if (!StringUtils.isBlank(tableid)) { + map.put("fktableidList", tablePropertiesRes.findByDbtableid(tableid)); + } + return request(super.createRequestPageTempletResponse("/apps/business/report/cube/cubelevel/fktableiddiv")); + } +} diff --git a/contact-center/app/src/main/java/com/chatopera/cc/controller/apps/report/CubeMeasureController.java b/contact-center/app/src/main/java/com/chatopera/cc/controller/apps/report/CubeMeasureController.java index f37acdb5..cf43d5c3 100644 --- a/contact-center/app/src/main/java/com/chatopera/cc/controller/apps/report/CubeMeasureController.java +++ b/contact-center/app/src/main/java/com/chatopera/cc/controller/apps/report/CubeMeasureController.java @@ -1,121 +1,122 @@ -/* - * Copyright (C) 2017 优客服-多渠道客服系统 - * Modifications copyright (C) 2018-2019 Chatopera Inc, - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.chatopera.cc.controller.apps.report; - -import com.chatopera.cc.controller.Handler; -import com.chatopera.cc.model.CubeMeasure; -import com.chatopera.cc.model.CubeMetadata; -import com.chatopera.cc.persistence.repository.CubeMeasureRepository; -import com.chatopera.cc.persistence.repository.CubeMetadataRepository; -import com.chatopera.cc.persistence.repository.TablePropertiesRepository; -import com.chatopera.cc.util.Menu; -import org.apache.commons.lang.StringUtils; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.stereotype.Controller; -import org.springframework.ui.ModelMap; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.servlet.ModelAndView; - -import javax.servlet.http.HttpServletRequest; -import javax.validation.Valid; -import java.util.List; - -@Controller -@RequestMapping("/apps/report/cubemeasure") -public class CubeMeasureController extends Handler{ - - @Autowired - private CubeMeasureRepository cubeMeasureRes; - - @Autowired - private TablePropertiesRepository tablePropertiesRes; - - @Autowired - private CubeMetadataRepository cubeMetadataRes; - - @RequestMapping("/add") - @Menu(type = "report" , subtype = "cubemeasure") - public ModelAndView cubeMeasureadd(ModelMap map , HttpServletRequest request , @Valid String cubeid) { - map.addAttribute("cubeid", cubeid); - List cmList = cubeMetadataRes.findByCubeidAndMtype(cubeid,"0"); - if(!cmList.isEmpty() && cmList.get(0)!=null) { - map.put("fktableidList", tablePropertiesRes.findByDbtableid(cmList.get(0).getTb().getId())); - map.put("table", cmList.get(0).getTb()); - } - return request(super.createRequestPageTempletResponse("/apps/business/report/cube/cubemeasure/add")); - } - - @RequestMapping("/save") - @Menu(type = "report" , subtype = "cubemeasure" ) - public ModelAndView cubeMeasuresave(ModelMap map , HttpServletRequest request , @Valid CubeMeasure cubeMeasure) { - if(!StringUtils.isBlank(cubeMeasure.getName())){ - cubeMeasure.setOrgi(super.getOrgi(request)); - cubeMeasure.setCreater(super.getUser(request).getId()); - cubeMeasure.setCode(cubeMeasure.getColumname()); - cubeMeasureRes.save(cubeMeasure) ; - } - return request(super.createRequestPageTempletResponse("redirect:/apps/report/cube/detail.html?dimensionId=cubemeasure&id="+cubeMeasure.getCubeid())); - } - - @RequestMapping("/delete") - @Menu(type = "report" , subtype = "cubemeasure" ) - public ModelAndView quickreplydelete(ModelMap map , HttpServletRequest request , @Valid String id) { - CubeMeasure cubeMeasure = cubeMeasureRes.findOne(id) ; - if(cubeMeasure!=null){ - cubeMeasureRes.delete(cubeMeasure); - } - return request(super.createRequestPageTempletResponse("redirect:/apps/report/cube/detail.html?dimensionId=cubemeasure&id="+cubeMeasure.getCubeid())); - } - @RequestMapping("/edit") - @Menu(type = "report" , subtype = "cubemeasure" , admin= true) - public ModelAndView quickreplyedit(ModelMap map , HttpServletRequest request , @Valid String id) { - CubeMeasure cubeMeasure = cubeMeasureRes.findOne(id) ; - map.put("cubemeasure", cubeMeasure) ; - if(cubeMeasure!=null) { - List cmList = cubeMetadataRes.findByCubeidAndMtype(cubeMeasure.getCubeid(),"0"); - if(!cmList.isEmpty() && cmList.get(0)!=null) { - map.put("fktableidList", tablePropertiesRes.findByDbtableid(cmList.get(0).getTb().getId())); - map.put("table", cmList.get(0).getTb()); - } - } - return request(super.createRequestPageTempletResponse("/apps/business/report/cube/cubemeasure/edit")); - } - - @RequestMapping("/update") - @Menu(type = "report" , subtype = "cubemeasure" , admin= true) - public ModelAndView quickreplyupdate(ModelMap map , HttpServletRequest request , @Valid CubeMeasure cubeMeasure) { - if(!StringUtils.isBlank(cubeMeasure.getId())){ - CubeMeasure temp = cubeMeasureRes.findOne(cubeMeasure.getId()) ; - cubeMeasure.setOrgi(super.getOrgi(request)); - cubeMeasure.setCreater(super.getUser(request).getId()); - if(temp!=null){ - cubeMeasure.setCreatetime(temp.getCreatetime()); - } - cubeMeasure.setCode(cubeMeasure.getColumname()); - cubeMeasureRes.save(cubeMeasure) ; - } - return request(super.createRequestPageTempletResponse("redirect:/apps/report/cube/detail.html?dimensionId=cubemeasure&id="+cubeMeasure.getCubeid())); - } - @RequestMapping("/fktableid") - @Menu(type = "report" , subtype = "cubemeasure" , admin= true) - public ModelAndView fktableid(ModelMap map , HttpServletRequest request , @Valid String tableid) { - if(!StringUtils.isBlank(tableid)){ - map.put("fktableidList", tablePropertiesRes.findByDbtableid(tableid)); - } - return request(super.createRequestPageTempletResponse("/apps/business/report/cube/cubemeasure/fktableiddiv")); - } -} \ No newline at end of file +/* + * Copyright (C) 2017 优客服-多渠道客服系统 + * Modifications copyright (C) 2018-2019 Chatopera Inc, + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.chatopera.cc.controller.apps.report; + +import com.chatopera.cc.controller.Handler; +import com.chatopera.cc.model.CubeMeasure; +import com.chatopera.cc.model.CubeMetadata; +import com.chatopera.cc.persistence.repository.CubeMeasureRepository; +import com.chatopera.cc.persistence.repository.CubeMetadataRepository; +import com.chatopera.cc.persistence.repository.TablePropertiesRepository; +import com.chatopera.cc.util.Menu; +import lombok.RequiredArgsConstructor; +import org.apache.commons.lang.StringUtils; +import org.springframework.http.HttpStatus; +import org.springframework.stereotype.Controller; +import org.springframework.ui.ModelMap; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.server.ResponseStatusException; +import org.springframework.web.servlet.ModelAndView; + +import javax.servlet.http.HttpServletRequest; +import javax.validation.Valid; +import java.util.List; + +@Controller +@RequestMapping("/apps/report/cubemeasure") +@RequiredArgsConstructor +public class CubeMeasureController extends Handler { + + @org.springframework.lang.NonNull + private final CubeMeasureRepository cubeMeasureRes; + + @org.springframework.lang.NonNull + private final TablePropertiesRepository tablePropertiesRes; + + @org.springframework.lang.NonNull + private final CubeMetadataRepository cubeMetadataRes; + + @RequestMapping("/add") + @Menu(type = "report", subtype = "cubemeasure") + public ModelAndView cubeMeasureadd(ModelMap map, @Valid String cubeid) { + map.addAttribute("cubeid", cubeid); + List cmList = cubeMetadataRes.findByCubeidAndMtype(cubeid, "0"); + if (!cmList.isEmpty() && cmList.get(0) != null) { + map.put("fktableidList", tablePropertiesRes.findByDbtableid(cmList.get(0).getTb().getId())); + map.put("table", cmList.get(0).getTb()); + } + return request(super.createRequestPageTempletResponse("/apps/business/report/cube/cubemeasure/add")); + } + + @RequestMapping("/save") + @Menu(type = "report", subtype = "cubemeasure") + public ModelAndView cubeMeasuresave(HttpServletRequest request, @Valid CubeMeasure cubeMeasure) { + if (!StringUtils.isBlank(cubeMeasure.getName())) { + cubeMeasure.setOrgi(super.getOrgi(request)); + cubeMeasure.setCreater(super.getUser(request).getId()); + cubeMeasure.setCode(cubeMeasure.getColumname()); + cubeMeasureRes.save(cubeMeasure); + } + return request(super.createRequestPageTempletResponse("redirect:/apps/report/cube/detail.html?dimensionId=cubemeasure&id=" + cubeMeasure.getCubeid())); + } + + @RequestMapping("/delete") + @Menu(type = "report", subtype = "cubemeasure") + public ModelAndView quickreplydelete(@Valid String id) { + cubeMeasureRes.deleteById(id); + CubeMeasure cubeMeasure = cubeMeasureRes.findById(id) + .orElseThrow(() -> new ResponseStatusException(HttpStatus.NOT_FOUND, String.format("Cube measure %s not found", id))); + return request(super.createRequestPageTempletResponse("redirect:/apps/report/cube/detail.html?dimensionId=cubemeasure&id=" + cubeMeasure.getCubeid())); + } + + @RequestMapping("/edit") + @Menu(type = "report", subtype = "cubemeasure", admin = true) + public ModelAndView quickreplyedit(ModelMap map, @Valid String id) { + CubeMeasure cubeMeasure = cubeMeasureRes.findById(id).orElse(null); + map.put("cubemeasure", cubeMeasure); + if (cubeMeasure != null) { + List cmList = cubeMetadataRes.findByCubeidAndMtype(cubeMeasure.getCubeid(), "0"); + if (!cmList.isEmpty() && cmList.get(0) != null) { + map.put("fktableidList", tablePropertiesRes.findByDbtableid(cmList.get(0).getTb().getId())); + map.put("table", cmList.get(0).getTb()); + } + } + return request(super.createRequestPageTempletResponse("/apps/business/report/cube/cubemeasure/edit")); + } + + @RequestMapping("/update") + @Menu(type = "report", subtype = "cubemeasure", admin = true) + public ModelAndView quickreplyupdate(HttpServletRequest request, @Valid CubeMeasure cubeMeasure) { + if (!StringUtils.isBlank(cubeMeasure.getId())) { + cubeMeasure.setOrgi(super.getOrgi(request)); + cubeMeasure.setCreater(super.getUser(request).getId()); + cubeMeasureRes.findById(cubeMeasure.getId()).ifPresent(temp -> cubeMeasure.setCreatetime(temp.getCreatetime())); + cubeMeasure.setCode(cubeMeasure.getColumname()); + cubeMeasureRes.save(cubeMeasure); + } + return request(super.createRequestPageTempletResponse("redirect:/apps/report/cube/detail.html?dimensionId=cubemeasure&id=" + cubeMeasure.getCubeid())); + } + + @RequestMapping("/fktableid") + @Menu(type = "report", subtype = "cubemeasure", admin = true) + public ModelAndView fktableid(ModelMap map, @Valid String tableid) { + if (!StringUtils.isBlank(tableid)) { + map.put("fktableidList", tablePropertiesRes.findByDbtableid(tableid)); + } + return request(super.createRequestPageTempletResponse("/apps/business/report/cube/cubemeasure/fktableiddiv")); + } +} diff --git a/contact-center/app/src/main/java/com/chatopera/cc/controller/apps/report/DimensionController.java b/contact-center/app/src/main/java/com/chatopera/cc/controller/apps/report/DimensionController.java index 85509b9e..3d126a52 100644 --- a/contact-center/app/src/main/java/com/chatopera/cc/controller/apps/report/DimensionController.java +++ b/contact-center/app/src/main/java/com/chatopera/cc/controller/apps/report/DimensionController.java @@ -1,124 +1,126 @@ -/* - * Copyright (C) 2017 优客服-多渠道客服系统 - * Modifications copyright (C) 2018-2019 Chatopera Inc, - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.chatopera.cc.controller.apps.report; - -import com.chatopera.cc.controller.Handler; -import com.chatopera.cc.model.CubeLevel; -import com.chatopera.cc.model.CubeMetadata; -import com.chatopera.cc.model.Dimension; -import com.chatopera.cc.persistence.repository.CubeLevelRepository; -import com.chatopera.cc.persistence.repository.CubeMetadataRepository; -import com.chatopera.cc.persistence.repository.DimensionRepository; -import com.chatopera.cc.persistence.repository.TablePropertiesRepository; -import com.chatopera.cc.util.Menu; -import org.apache.commons.lang.StringUtils; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.stereotype.Controller; -import org.springframework.ui.ModelMap; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.servlet.ModelAndView; - -import javax.servlet.http.HttpServletRequest; -import javax.validation.Valid; -import java.util.List; - -@Controller -@RequestMapping("/apps/report/dimension") -public class DimensionController extends Handler{ - - @Autowired - private DimensionRepository dimensionRes; - - @Autowired - private CubeLevelRepository cubeLevelRes; - - @Autowired - private CubeMetadataRepository cubeMetadataRes; - - @Autowired - private TablePropertiesRepository tablePropertiesRes; - - @RequestMapping("/add") - @Menu(type = "report" , subtype = "dimension") - public ModelAndView dimensionadd(ModelMap map , HttpServletRequest request , @Valid String cubeid) { - map.addAttribute("cubeid", cubeid); - map.addAttribute("fkfieldList",cubeMetadataRes.findByCubeidAndMtype(cubeid,"0")); - map.addAttribute("fktableList",cubeMetadataRes.findByCubeidAndMtypeNot(cubeid,"0")); - return request(super.createRequestPageTempletResponse("/apps/business/report/cube/dimension/add")); - } - - @RequestMapping("/save") - @Menu(type = "report" , subtype = "dimension" ) - public ModelAndView dimensionsave(ModelMap map , HttpServletRequest request , @Valid Dimension dimension) { - if(!StringUtils.isBlank(dimension.getName())){ - dimension.setOrgi(super.getOrgi(request)); - dimension.setCreater(super.getUser(request).getId()); - dimensionRes.save(dimension) ; - } - return request(super.createRequestPageTempletResponse("redirect:/apps/report/cube/detail.html?id="+dimension.getCubeid()+"&dimensionId="+dimension.getId())); - } - - @RequestMapping("/delete") - @Menu(type = "report" , subtype = "dimension" ) - public ModelAndView quickreplydelete(ModelMap map , HttpServletRequest request , @Valid String id) { - Dimension dimension = dimensionRes.findOne(id) ; - if(dimension!=null){ - dimensionRes.delete(dimension); - List cubeLevelList = cubeLevelRes.findByOrgiAndDimid(super.getOrgi(request), id); - if(!cubeLevelList.isEmpty()) { - cubeLevelRes.delete(cubeLevelList); - } - } - return request(super.createRequestPageTempletResponse("redirect:/apps/report/cube/detail.html?id="+dimension.getCubeid())); - } - @RequestMapping("/edit") - @Menu(type = "report" , subtype = "dimension" , admin= true) - public ModelAndView quickreplyedit(ModelMap map , HttpServletRequest request , @Valid String id) { - Dimension dimension = dimensionRes.findOne(id) ; - map.put("dimension", dimension) ; - String cubeid = dimension.getCubeid(); - map.addAttribute("cubeid", cubeid); - map.addAttribute("fkfieldList",cubeMetadataRes.findByCubeidAndMtype(cubeid,"0")); - List fktableList = cubeMetadataRes.findByCubeidAndMtypeNot(cubeid,"0"); - map.addAttribute("fktableList",fktableList); - map.put("fktableidList", tablePropertiesRes.findByDbtableid(dimension.getFktable())); - return request(super.createRequestPageTempletResponse("/apps/business/report/cube/dimension/edit")); - } - - @RequestMapping("/update") - @Menu(type = "report" , subtype = "dimension" , admin= true) - public ModelAndView quickreplyupdate(ModelMap map , HttpServletRequest request , @Valid Dimension dimension) { - if(!StringUtils.isBlank(dimension.getId())){ - Dimension temp = dimensionRes.findOne(dimension.getId()) ; - dimension.setOrgi(super.getOrgi(request)); - dimension.setCreater(super.getUser(request).getId()); - if(temp!=null){ - dimension.setCreatetime(temp.getCreatetime()); - } - dimensionRes.save(dimension) ; - } - return request(super.createRequestPageTempletResponse("redirect:/apps/report/cube/detail.html?id="+dimension.getCubeid()+"&dimensionId="+dimension.getId())); - } - @RequestMapping("/fktableid") - @Menu(type = "report" , subtype = "dimension" , admin= true) - public ModelAndView fktableid(ModelMap map , HttpServletRequest request , @Valid String tableid) { - if(!StringUtils.isBlank(tableid)){ - map.put("fktableidList", tablePropertiesRes.findByDbtableid(tableid)); - } - return request(super.createRequestPageTempletResponse("/apps/business/report/cube/dimension/fktableiddiv")); - } -} \ No newline at end of file +/* + * Copyright (C) 2017 优客服-多渠道客服系统 + * Modifications copyright (C) 2018-2019 Chatopera Inc, + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.chatopera.cc.controller.apps.report; + +import com.chatopera.cc.controller.Handler; +import com.chatopera.cc.model.CubeLevel; +import com.chatopera.cc.model.CubeMetadata; +import com.chatopera.cc.model.Dimension; +import com.chatopera.cc.persistence.repository.CubeLevelRepository; +import com.chatopera.cc.persistence.repository.CubeMetadataRepository; +import com.chatopera.cc.persistence.repository.DimensionRepository; +import com.chatopera.cc.persistence.repository.TablePropertiesRepository; +import com.chatopera.cc.util.Menu; +import lombok.RequiredArgsConstructor; +import org.apache.commons.lang.StringUtils; +import org.springframework.http.HttpStatus; +import org.springframework.stereotype.Controller; +import org.springframework.ui.ModelMap; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.server.ResponseStatusException; +import org.springframework.web.servlet.ModelAndView; + +import javax.servlet.http.HttpServletRequest; +import javax.validation.Valid; +import java.util.List; + +@Controller +@RequestMapping("/apps/report/dimension") +@RequiredArgsConstructor +public class DimensionController extends Handler { + + @org.springframework.lang.NonNull + private final DimensionRepository dimensionRes; + + @org.springframework.lang.NonNull + private final CubeLevelRepository cubeLevelRes; + + @org.springframework.lang.NonNull + private final CubeMetadataRepository cubeMetadataRes; + + @org.springframework.lang.NonNull + private final TablePropertiesRepository tablePropertiesRes; + + @RequestMapping("/add") + @Menu(type = "report", subtype = "dimension") + public ModelAndView dimensionadd(ModelMap map, @Valid String cubeid) { + map.addAttribute("cubeid", cubeid); + map.addAttribute("fkfieldList", cubeMetadataRes.findByCubeidAndMtype(cubeid, "0")); + map.addAttribute("fktableList", cubeMetadataRes.findByCubeidAndMtypeNot(cubeid, "0")); + return request(super.createRequestPageTempletResponse("/apps/business/report/cube/dimension/add")); + } + + @RequestMapping("/save") + @Menu(type = "report", subtype = "dimension") + public ModelAndView dimensionsave(HttpServletRequest request, @Valid Dimension dimension) { + if (!StringUtils.isBlank(dimension.getName())) { + dimension.setOrgi(super.getOrgi(request)); + dimension.setCreater(super.getUser(request).getId()); + dimensionRes.save(dimension); + } + return request(super.createRequestPageTempletResponse("redirect:/apps/report/cube/detail.html?id=" + dimension.getCubeid() + "&dimensionId=" + dimension.getId())); + } + + @RequestMapping("/delete") + @Menu(type = "report", subtype = "dimension") + public ModelAndView quickreplydelete(HttpServletRequest request, @Valid String id) { + Dimension dimension = dimensionRes.findById(id) + .orElseThrow(() -> new ResponseStatusException(HttpStatus.NOT_FOUND, String.format("Dimension %s not found", id))); + dimensionRes.delete(dimension); + List cubeLevelList = cubeLevelRes.findByOrgiAndDimid(super.getOrgi(request), id); + if (!cubeLevelList.isEmpty()) { + cubeLevelRes.deleteAll(cubeLevelList); + } + return request(super.createRequestPageTempletResponse("redirect:/apps/report/cube/detail.html?id=" + dimension.getCubeid())); + } + + @RequestMapping("/edit") + @Menu(type = "report", subtype = "dimension", admin = true) + public ModelAndView quickreplyedit(ModelMap map, @Valid String id) { + Dimension dimension = dimensionRes.findById(id) + .orElseThrow(() -> new ResponseStatusException(HttpStatus.NOT_FOUND, String.format("Dimension %s not found", id))); + map.put("dimension", dimension); + String cubeid = dimension.getCubeid(); + map.addAttribute("cubeid", cubeid); + map.addAttribute("fkfieldList", cubeMetadataRes.findByCubeidAndMtype(cubeid, "0")); + List fktableList = cubeMetadataRes.findByCubeidAndMtypeNot(cubeid, "0"); + map.addAttribute("fktableList", fktableList); + map.put("fktableidList", tablePropertiesRes.findByDbtableid(dimension.getFktable())); + return request(super.createRequestPageTempletResponse("/apps/business/report/cube/dimension/edit")); + } + + @RequestMapping("/update") + @Menu(type = "report", subtype = "dimension", admin = true) + public ModelAndView quickreplyupdate(HttpServletRequest request, @Valid Dimension dimension) { + if (!StringUtils.isBlank(dimension.getId())) { + dimension.setOrgi(super.getOrgi(request)); + dimension.setCreater(super.getUser(request).getId()); + dimensionRes.findById(dimension.getId()).ifPresent(it -> dimension.setCreatetime(it.getCreatetime())); + dimensionRes.save(dimension); + } + return request(super.createRequestPageTempletResponse("redirect:/apps/report/cube/detail.html?id=" + dimension.getCubeid() + "&dimensionId=" + dimension.getId())); + } + + @RequestMapping("/fktableid") + @Menu(type = "report", subtype = "dimension", admin = true) + public ModelAndView fktableid(ModelMap map, @Valid String tableid) { + if (!StringUtils.isBlank(tableid)) { + map.put("fktableidList", tablePropertiesRes.findByDbtableid(tableid)); + } + return request(super.createRequestPageTempletResponse("/apps/business/report/cube/dimension/fktableiddiv")); + } +} diff --git a/contact-center/app/src/main/java/com/chatopera/cc/controller/apps/report/ReportDesignController.java b/contact-center/app/src/main/java/com/chatopera/cc/controller/apps/report/ReportDesignController.java index d8b8a30a..6c20ae8e 100644 --- a/contact-center/app/src/main/java/com/chatopera/cc/controller/apps/report/ReportDesignController.java +++ b/contact-center/app/src/main/java/com/chatopera/cc/controller/apps/report/ReportDesignController.java @@ -1,1271 +1,1273 @@ -/* - * Copyright (C) 2017 优客服-多渠道客服系统 - * Modifications copyright (C) 2018-2019 Chatopera Inc, - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.chatopera.cc.controller.apps.report; - -import com.chatopera.cc.basic.Constants; -import com.chatopera.cc.basic.MainContext; -import com.chatopera.cc.basic.MainUtils; -import com.chatopera.cc.controller.Handler; -import com.chatopera.cc.model.*; -import com.chatopera.cc.persistence.repository.*; -import com.chatopera.cc.util.Menu; -import com.chatopera.cc.util.bi.ReportData; -import org.apache.commons.codec.binary.Base64; -import org.apache.commons.lang.exception.ExceptionUtils; -import org.apache.commons.lang3.StringUtils; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.beans.factory.annotation.Value; -import org.springframework.stereotype.Controller; -import org.springframework.ui.ModelMap; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.servlet.ModelAndView; - -import javax.servlet.http.HttpServletRequest; -import javax.validation.Valid; -import java.util.*; - -@Controller -@RequestMapping("/apps/report/design") -public class ReportDesignController extends Handler { - - @Value("${web.upload-path}") - private String path; - - @Value("${uk.im.server.port}") - private Integer port; - - @Autowired - private TemplateRepository templateRes; - - @Autowired - private ReportRepository reportRes; - - @Autowired - private ReportModelRepository reportModelRes; - - @Autowired - private PublishedCubeRepository publishedCubeRepository; - - @Autowired - private ColumnPropertiesRepository columnPropertiesRepository; - - - @Autowired - private ReportFilterRepository reportFilterRepository; - - @Autowired - private ReportCubeService reportCubeService; - - @Autowired - private TablePropertiesRepository tablePropertiesRes; - - @Autowired - private PublishedReportRepository publishedReportRes; - - @Autowired - private SysDicRepository sysDicRes; - @Autowired - private MetadataRepository metadataRes; - - @RequestMapping("/index") - @Menu(type = "report", subtype = "reportdesign") - public ModelAndView index(ModelMap map, HttpServletRequest request, @Valid String q, @Valid String id) throws Exception { - List tpDicList = Dict.getInstance().getDic(Constants.CSKEFU_SYSTEM_DIC); - for (SysDic sysDic : tpDicList) { - if (sysDic.getCode().equals("layout")) { - map.addAttribute("layoutList", - templateRes.findByTemplettypeAndOrgi(sysDic.getId(), super.getOrgi(request))); - } else if (sysDic.getCode().equals("report")) { - map.addAttribute("reportList", - templateRes.findByTemplettypeAndOrgi(sysDic.getId(), super.getOrgi(request))); - } else if (sysDic.getCode().equals("filter")) { - map.addAttribute("filterList", - templateRes.findByTemplettypeAndOrgi(sysDic.getId(), super.getOrgi(request))); - } - } - - if (!StringUtils.isBlank(id)) { - map.addAttribute("report", reportRes.findByIdAndOrgi(id, super.getOrgi(request))); - map.addAttribute("reportModels", reportModelRes.findByOrgiAndReportid(super.getOrgi(request), id)); - - List listFilters = reportFilterRepository.findByReportidAndFiltertypeAndOrgi(id, "report", super.getOrgi(request)); - if(!listFilters.isEmpty()) { - Map filterMap = new HashMap(); - for(ReportFilter rf:listFilters) { - filterMap.put(rf.getId(), rf); - } - for(ReportFilter rf:listFilters) { - if(!StringUtils.isBlank(rf.getCascadeid())) { - rf.setChildFilter(filterMap.get(rf.getCascadeid())); - } - } - } - map.addAttribute("reportFilters", reportCubeService.fillReportFilterData(listFilters, request)); - } - return request(super.createRequestPageTempletResponse("/apps/business/report/design/index")); - } - - /** - * 请求 报表的模板组件, 请求的时候,生成个报表组件,报表组件 需要存放在列的对应关系中 - * - * @param map - * @param request - * @param template - * @param id - * @return - * @throws Exception - */ - @RequestMapping("/rtpl") - @Menu(type = "report", subtype = "reportdesign") - public ModelAndView rtpl(ModelMap map, HttpServletRequest request, @Valid String tplname, @Valid String template, - @Valid String colindex, @Valid String id, @Valid String parentid, @Valid String mid) throws Exception { - Template tp = templateRes.findByIdAndOrgi(template, super.getOrgi(request)); - map.addAttribute("eltemplet", tp); - if (!StringUtils.isBlank(parentid)) { - ReportModel model = new ReportModel(); - model.setOrgi(super.getOrgi(request)); - model.setCreatetime(new Date()); - model.setReportid(id); - model.setParentid(parentid); - model.setName(tplname); - if (!StringUtils.isBlank(colindex) && colindex.matches("[\\d]{1,}")) { - model.setColindex(Integer.parseInt(colindex)); - } else { - model.setColindex(1); - } - ChartProperties chartProperties = new ChartProperties(); - chartProperties.setChartype(tp.getCharttype()); - Base64 base64 = new Base64(); - model.setChartcontent(base64.encodeToString(MainUtils.toBytes(chartProperties))) ; - model.setTempletid(template); - model.setMid(mid); - - reportModelRes.save(model); - map.addAttribute("element", model); - } - return request(super.createRequestPageTempletResponse("/apps/business/report/design/element")); - } - - /** - * 请求 报表的模板组件, 请求的时候,生成个报表组件,报表组件 需要存放在列的对应关系中 - * - * @param map - * @param request - * @param template - * @param id - * @return - */ - @RequestMapping("/element") - @Menu(type = "report", subtype = "reportdesign") - public ModelAndView element(ModelMap map, HttpServletRequest request, @Valid String colindex, @Valid String id, - @Valid String parentid, @Valid String mid) { - - if (!StringUtils.isBlank(id) && !StringUtils.isBlank(parentid)) { - ReportModel model = reportModelRes.findByIdAndOrgi(id, super.getOrgi(request)); - if (model != null) { - model.setParentid(parentid); - if (!StringUtils.isBlank(colindex) && colindex.matches("[\\d]{1,}")) { - model.setColindex(Integer.parseInt(colindex)); - } else { - model.setColindex(1); - } - reportModelRes.save(model); - } - } - return request(super.createRequestPageTempletResponse("/public/success")); - } - - /** - * 请求 布局的模板组件 , 请求的时候,生成一个布局记录,布局记录分两个部分,一个是行,一个是列 ,一次请求,创建一条行记录(ROW)和多个列记录(COL) - * 行记录和列记录都存放到 ES中 - * - * @param map - * @param request - * @param template - * @param id - * @return - */ - @RequestMapping("/ltpl") - @Menu(type = "report", subtype = "reportdesign") - public ModelAndView ltpl(ModelMap map, HttpServletRequest request, @Valid String template, @Valid String id, - @Valid String mid, @Valid String colspan) { - map.addAttribute("templet", templateRes.findByIdAndOrgi(template, super.getOrgi(request))); - ReportModel model = new ReportModel(); - model.setOrgi(super.getOrgi(request)); - model.setCreatetime(new Date()); - model.setReportid(id); - model.setParentid(id); - - if (!StringUtils.isBlank(colspan) && colspan.matches("[\\d]{1,}")) { - model.setColspan(Integer.parseInt(colspan)); - } else { - model.setColspan(4); - } - model.setTempletid(template); - model.setMid(mid); - - reportModelRes.save(model); - map.addAttribute("model", model); - - return request(super.createRequestPageTempletResponse("/apps/business/report/design/layout")); - } - /** - * 请求 过滤器的模板组件, 请求的时候,生成个过滤器组件 - * - * @param map - * @param request - * @param template - * @param id - * @return - */ - @RequestMapping("/ftpl") - @Menu(type = "report", subtype = "reportdesign") - public ModelAndView ftpl(ModelMap map, HttpServletRequest request, @Valid String tplname, @Valid String template, - @Valid String colindex, @Valid String id, @Valid String parentid, @Valid String mid) { - Template t = templateRes.findByIdAndOrgi(template, super.getOrgi(request)); - map.addAttribute("eltemplet",t); - if (!StringUtils.isBlank(parentid)) { - ReportFilter filter = new ReportFilter(); - filter.setCode(MainUtils.genID()); - filter.setReportid(id); - filter.setOrgi(super.getOrgi(request)); - filter.setCreatetime(new Date()); - filter.setName(t.getName()); - filter.setDataname(t.getName()); - filter.setTitle(t.getName()); - filter.setFiltertype("report"); - filter.setFuntype("filter"); - filter.setFiltertemplet(template); - filter.setModelid(mid); - filter.setModeltype(t.getCode()); - - filter.setConvalue(MainContext.FilterConValueType.INPUT.toString()); - filter.setValuefiltertype(MainContext.FilterValuefilterType.COMPARE.toString()); - filter.setComparetype(MainContext.FilterCompType.EQUAL.toString()); - filter.setFormatstr("yyyy-MM-dd"); - reportFilterRepository.save(filter); - map.addAttribute("filter", filter); - } - return request(super.createRequestPageTempletResponse("/apps/business/report/design/filter")); - } - /** - * 删除模板组件 - * - * @param map - * @param request - * @param id - * @return - */ - @RequestMapping("/modeldelete") - @Menu(type = "report", subtype = "reportdesign") - public ModelAndView modeldelete(ModelMap map, HttpServletRequest request, @Valid String id) { - ReportModel model = reportModelRes.findByIdAndOrgi(id, super.getOrgi(request)); - if (model != null) { - List childsList = reportModelRes.findByParentidAndOrgi(model.getId(), super.getOrgi(request)); - if (!childsList.isEmpty()) { - reportModelRes.delete(childsList); - } - reportModelRes.delete(model); - } - return request(super.createRequestPageTempletResponse("/public/success")); - } - - /** - * 组件设计 - * - * @param map - * @param request - * @param id - * @return - * @throws Exception - */ - @RequestMapping("/modeldesign") - @Menu(type = "report", subtype = "reportdesign") - public ModelAndView modeldesign(ModelMap map, HttpServletRequest request, @Valid String id, @Valid String tabid , HashMap semap) - throws Exception { - List tpDicList = Dict.getInstance().getDic(Constants.CSKEFU_SYSTEM_DIC); - for (SysDic sysDic : tpDicList) { - if (sysDic.getCode().equals("report")) { - map.addAttribute("reportList", - templateRes.findByTemplettypeAndOrgi(sysDic.getId(), super.getOrgi(request))); - } - } - - ReportModel model = this.getModel(id, super.getOrgi(request)); - map.addAttribute("reportModel", model); - map.addAttribute("element", model); - if (model != null && !StringUtils.isBlank(model.getPublishedcubeid())) { - PublishedCube cube = publishedCubeRepository.findOne(model.getPublishedcubeid()); - map.addAttribute("cube", cube); - if (canGetReportData(model, cube.getCube())) { - ReportData reportData = null ; - try { - reportData = reportCubeService.getReportData(model, cube.getCube(), request, true,semap) ; - map.addAttribute("reportData",reportData); - }catch(Exception ex) { - map.addAttribute("msg",(ExceptionUtils.getMessage(ex).replaceAll("\r\n","") + ExceptionUtils.getRootCauseMessage(ex)).replaceAll("\"", "'")); - } - } - map.addAttribute("eltemplet", templateRes.findByIdAndOrgi(model.getTempletid(), super.getOrgi(request))); - } - map.addAttribute("tabid", tabid); - return request(super.createRequestPageTempletResponse("/apps/business/report/design/modeldesign")); - } - private boolean canGetReportData(ReportModel model,Cube cube) { - return !model.getProperties().isEmpty() || !model.getColproperties().isEmpty() || !model.getMeasures().isEmpty(); - } - private ReportModel getModel(String id,String orgi) { - ReportModel model = reportModelRes.findByIdAndOrgi(id, orgi); - if (model != null) { - model.setProperties( - columnPropertiesRepository.findByModelidAndCurOrderBySortindexAsc(model.getId(), "field")); - model.setColproperties( - columnPropertiesRepository.findByModelidAndCurOrderBySortindexAsc(model.getId(), "cfield")); - model.setMeasures( - columnPropertiesRepository.findByModelidAndCurOrderBySortindexAsc(model.getId(), "measure")); - List listFilters = reportFilterRepository.findByModelidOrderBySortindexAsc(model.getId()); - if(!listFilters.isEmpty()) { - for(ReportFilter rf:listFilters) { - if(!StringUtils.isBlank(rf.getCascadeid())) { - rf.setChildFilter(reportFilterRepository.findByIdAndOrgi(rf.getCascadeid(), orgi)); - } - } - } - model.setFilters(listFilters); - } - return model; - } - - /** - * 选择模型 - * - * @param request - * @return - * @throws Exception - */ - @RequestMapping("/dataset") - @Menu(type = "report", subtype = "reportdesign") - public ModelAndView dataset(ModelMap map, HttpServletRequest request, @Valid String mid, @Valid String cubeid) - throws Exception { - if (!StringUtils.isBlank(cubeid)) { - PublishedCube cube = publishedCubeRepository.findOne(cubeid); - map.put("cube", cube); - } - ReportModel model = this.getModel(mid, super.getOrgi(request)); - if (!StringUtils.isBlank(cubeid)) { - model.setPublishedcubeid(cubeid); - if(model!=null) { - columnPropertiesRepository.delete(model.getProperties()); - columnPropertiesRepository.delete(model.getColproperties()); - columnPropertiesRepository.delete(model.getMeasures()); - reportFilterRepository.delete(model.getFilters()); - } - } - reportModelRes.save(model); - map.put("reportModel", model); - return request(super.createRequestPageTempletResponse( - "redirect:/apps/report/design/modeldesign.html?id=" + model.getId())); - } - - @RequestMapping("/adddata") - @Menu(type = "report", subtype = "reportdesign") - public ModelAndView dimensionadd(ModelMap map, HttpServletRequest request, @Valid String cubeid, @Valid String t,@Valid String dtype, - @Valid String mid, @Valid String dim, @Valid String tabid) { - ModelAndView view = request( - super.createRequestPageTempletResponse("/apps/business/report/design/modeldesign/add")); - if (!StringUtils.isBlank(cubeid)) { - PublishedCube cube = publishedCubeRepository.findOne(cubeid); - map.addAttribute("cube", cube); - } - map.addAttribute("t", t); - ReportModel model = reportModelRes.findByIdAndOrgi(mid, super.getOrgi(request)); - if (!StringUtils.isBlank(cubeid)) { - model.setPublishedcubeid(cubeid); - } - map.addAttribute("reportModel", model); - map.addAttribute("dim", dim); - map.addAttribute("tabid", tabid); - map.addAttribute("dtype", dtype); - return view; - } - /** - * 添加过滤器 - * @param map - * @param request - * @return - */ - @RequestMapping("/filteradd") - @Menu(type = "report", subtype = "reportdesign") - public ModelAndView filteradd(ModelMap map, HttpServletRequest request, @Valid String cubeid,@Valid String dtype, - @Valid String mid) { - ModelAndView view = request( - super.createRequestPageTempletResponse("/apps/business/report/design/modeldesign/filteradd")); - if (!StringUtils.isBlank(cubeid)) { - PublishedCube cube = publishedCubeRepository.findOne(cubeid); - map.addAttribute("cube", cube); - List metadataTable = new ArrayList<>(); - for(CubeMetadata cm:cube.getCube().getMetadata()) { - if("0".equals(cm.getMtype())) { - map.addAttribute("table",cm.getTb()); - map.addAttribute("fieldList",cm.getTb().getTableproperty()); - } - metadataTable.add(cm.getTb()); - } - map.addAttribute("fktableList",metadataTable); - } - map.addAttribute("sysdicList", sysDicRes.findByParentid("0")) ; - map.addAttribute("mid", mid); - map.addAttribute("dtype", dtype); - return view; - } - /** - * 保存过滤器 - * - * @param map - * @param request - * @return - */ - @RequestMapping("/filtersave") - @Menu(type = "report", subtype = "reportdesign") - public ModelAndView filterupfiltersavedate(ModelMap map, HttpServletRequest request, @Valid ReportFilter f,@Valid String tbppy) { - String modelId = ""; - if (f != null) { - if(StringUtils.isBlank(f.getCode())) { - f.setCode(MainUtils.genID()); - } - f.setOrgi(super.getOrgi(request)); - f.setCreatetime(new Date()); - f.setName(f.getTitle()); - f.setDataname(f.getTitle()); - if(MainContext.FilterConValueType.AUTO.toString().equals(f.getConvalue()) && MainContext.FilterModelType.SIGSEL.toString().equals(f.getModeltype())) { - f.setCascadeid(f.getCascadeid()); - f.setTableproperty(null); - if(!StringUtils.isBlank(tbppy)) { - TableProperties t = new TableProperties(); - t.setId(tbppy); - f.setTableproperty(t); - } - }else { - f.setCascadeid(null); - f.setTableproperty(null); - } - modelId = f.getModelid(); - reportFilterRepository.save(f); - } - return request(super.createRequestPageTempletResponse( - "redirect:/apps/report/design/modeldesign.html?id=" + modelId + "&tabid=filter")); - } - @RequestMapping("/gettableid") - @Menu(type = "report" , subtype = "reportdesign") - public ModelAndView gettableid(ModelMap map , HttpServletRequest request , @Valid String tableid) { - if(!StringUtils.isBlank(tableid)){ - map.put("fktableidList", tablePropertiesRes.findByDbtableid(tableid)); - } - return request(super.createRequestPageTempletResponse("/apps/business/report/design/modeldesign/fktableid")); - } - @RequestMapping("/values") - @Menu(type = "report", subtype = "reportdesign") - public ModelAndView values(ModelMap map, HttpServletRequest request, @Valid String mid, @Valid String dsid, - @Valid String t, @Valid String d,@Valid String dtype, @Valid String m, @Valid String f, @Valid String tabid) throws Exception { - ReportModel model = this.getModel(mid, super.getOrgi(request)); - if (!StringUtils.isBlank(dsid)) { - model.setPublishedcubeid(dsid); - } - PublishedCube cube = publishedCubeRepository.findOne(dsid); - - if (!StringUtils.isBlank(d)) { - boolean inlist = false; - ColumnProperties currCp = null; - if (cube != null && cube.getCube() != null && cube.getCube().getDimension().size() > 0) { - for (ColumnProperties level : model.getProperties()) { - if (level.getDataid().equals(d)) { - inlist = true; - currCp = level; - break; - } - } - for (ColumnProperties level : model.getColproperties()) { - if (level.getDataid().equals(d)) { - inlist = true; - currCp = level; - break; - } - } - if (!inlist) { - ColumnProperties col = new ColumnProperties(); - if(StringUtils.isBlank(dtype)) { - col.setCur("field"); // 数据结构字段 - }else{ - col.setCur(dtype); - } - col.setId(MainUtils.genID()); - CubeLevel cubeLevel = null; - for (Dimension dim : cube.getCube().getDimension()) { - for (CubeLevel level : dim.getCubeLevel()) { - if (level.getId().equals(d)) { - cubeLevel = level; - break; - } - } - } - if (cubeLevel != null) { - col.setDataid(d); - col.setDataname(cubeLevel.getName()); - col.setColname(cubeLevel.getColumname()); - col.setTitle(cubeLevel.getName()); - } - col.setSortindex(("cfield".equals(dtype))?model.getColproperties().size()+1:model.getProperties().size() + 1); - col.setOrgi(super.getOrgi(request)); - col.setModelid(model.getId()); - columnPropertiesRepository.save(col); - }else { - if(!StringUtils.isBlank(dtype)) { - currCp.setCur(dtype); - currCp.setSortindex(("cfield".equals(dtype))?model.getColproperties().size()+1:model.getProperties().size() + 1); - columnPropertiesRepository.save(currCp); - } - } - } - } - if (!StringUtils.isBlank(m)) { - boolean inlist = false; - if (cube != null && cube.getCube() != null && cube.getCube().getMeasure().size() > 0) { - for (ColumnProperties measure : model.getMeasures()) { - if (measure.getDataid().equals(m)) { - inlist = true; - break; - } - } - if (!inlist) { - ColumnProperties col = new ColumnProperties(); - col.setCur("measure"); // 数据结构字段 - col.setId(MainUtils.genID()); - CubeMeasure cubeMeasure = null; - for (CubeMeasure measure : cube.getCube().getMeasure()) { - if (measure.getId().equals(m)) { - cubeMeasure = measure; - break; - } - } - if (cubeMeasure != null) { - col.setDataid(m); - col.setDataname(cubeMeasure.getName()); - col.setColname(cubeMeasure.getColumname()); - col.setTitle(cubeMeasure.getName()); - } - col.setSortindex(model.getMeasures().size() + 1); - col.setOrgi(super.getOrgi(request)); - col.setModelid(model.getId()); - model.getMeasures().add(col); - columnPropertiesRepository.save(col); - } - } - } - if (!StringUtils.isBlank(f)) { - boolean inlist = false; - if (cube != null && cube.getCube() != null && cube.getCube().getDimension().size() > 0) { - for (ReportFilter filter : model.getFilters()) { - if (filter.getDataid().equals(f)) { - inlist = true; - break; - } - } - if (!inlist) { - ReportFilter filter = new ReportFilter(); - filter.setId(MainUtils.genID()); - CubeLevel cubeLevel = null; - if (cube != null && cube.getCube() != null && cube.getCube().getDimension().size() > 0) { - for (Dimension dim : cube.getCube().getDimension()) { - for (CubeLevel level : dim.getCubeLevel()) { - if (level.getId().equals(f)) { - cubeLevel = level; - break; - } - } - } - if (cubeLevel != null) { - filter.setCubeid(cube.getId()); - filter.setDataid(cubeLevel.getId()); - filter.setDimid(cubeLevel.getDimid()); - filter.setLevel(cubeLevel); - filter.setDataname(cubeLevel.getName()); - filter.setTitle(cubeLevel.getName()); - filter.setModelid(mid); - - filter.setModeltype(MainContext.FilterModelType.TEXT.toString()); - filter.setConvalue(MainContext.FilterConValueType.INPUT.toString()); - filter.setValuefiltertype(MainContext.FilterValuefilterType.COMPARE.toString()); - filter.setComparetype(MainContext.FilterCompType.EQUAL.toString()); - - if ("select".equalsIgnoreCase(filter.getModeltype())) { - filter.setConvalue(MainContext.FilterConValueType.AUTO.toString()); - } - } - filter.setReportid(model.getReportid()); - filter.setSortindex(model.getFilters().size() + 1); - filter.setOrgi(super.getOrgi(request)); - model.getFilters().add(filter); - reportFilterRepository.save(filter); - } - } - } - } - return request(super.createRequestPageTempletResponse( - "redirect:/apps/report/design/modeldesign.html?id=" + model.getId() + "&tabid=" + tabid)); - } - - /** - * 异步 请求 报表的模板组件 - * - * @param map - * @param request - * @param template - * @param id - * @return - * @throws Exception - */ - @RequestMapping("/getelement") - @Menu(type = "report", subtype = "reportdesign") - public ModelAndView getelement(ModelMap map, HttpServletRequest request, @Valid String id,@Valid String publishedid, HashMap semap) throws Exception { - if (!StringUtils.isBlank(id)) { - ReportModel model = this.getModel(id, super.getOrgi(request),publishedid); - if(model!=null) { - map.addAttribute("eltemplet", MainUtils.getTemplate(model.getTempletid())); - } - map.addAttribute("element", model); - map.addAttribute("reportModel", model); - - if (model != null && !StringUtils.isBlank(model.getPublishedcubeid())) { - List cubeList = publishedCubeRepository.findByIdAndOrgi(model.getPublishedcubeid() , super.getOrgi(request)); - if(cubeList.size() > 0) { - PublishedCube cube = cubeList.get(0) ; - map.addAttribute("cube", cube); - if (canGetReportData(model, cube.getCube())) { - ReportData reportData = null ; - try { - reportData = reportCubeService.getReportData(model, cube.getCube(), request, true, semap) ; - map.addAttribute("reportData",reportData); - }catch(Exception ex) { - map.addAttribute("msg",ex.getMessage()); - } - } - } - } - } - return request(super.createRequestPageTempletResponse("/apps/business/report/design/elementajax")); - } - private ReportModel getModel(String id,String orgi,String publishedid) { - if(!StringUtils.isBlank(publishedid)) { - PublishedReport publishedReport = publishedReportRes.findById(publishedid); - if(publishedReport!=null) { - if(publishedReport.getReport()!=null && !publishedReport.getReport().getReportModels().isEmpty()) { - for(ReportModel rm :publishedReport.getReport().getReportModels()) { - if(rm.getId().equals(id)) { - return rm; - } - } - } - return this.getModel(id, orgi); - }else{ - return this.getModel(id, orgi); - } - }else { - return this.getModel(id, orgi); - } - - } - - /** - * 编辑报表过滤器 - * - * @param map - * @param request - * @return - * @throws Exception - */ - @RequestMapping("/rfilteredit") - @Menu(type = "report", subtype = "reportdesign") - public ModelAndView rfilteredit(ModelMap map, HttpServletRequest request, @Valid String fid) throws Exception { - map.addAttribute("sysdicList", sysDicRes.findByParentid("0")) ; - if (!StringUtils.isBlank(fid)) { - ReportFilter rf = reportFilterRepository.findByIdAndOrgi(fid, super.getOrgi(request)); - if(rf!=null) { - map.addAttribute("fktableList", metadataRes.findByOrgi(super.getOrgi(request))); - map.put("fktableidList", tablePropertiesRes.findByDbtableid(rf.getFktableid())); - if(!StringUtils.isBlank(rf.getCascadeid())) { - ReportFilter rfcas = reportFilterRepository.findByIdAndOrgi(rf.getCascadeid(), super.getOrgi(request)); - if(rfcas!=null) { - map.put("fktableiddivList", tablePropertiesRes.findByDbtableid(rfcas.getFktableid())); - } - } - } - map.addAttribute("reportFilter", rf); - map.addAttribute("reportFilters", reportCubeService.fillReportFilterData(reportFilterRepository.findByReportidAndFiltertypeAndOrgi(rf.getReportid(), "report", super.getOrgi(request)),request)); - } - return request(super.createRequestPageTempletResponse("/apps/business/report/design/filteredit")); - } - /** - * 编辑过滤器 - * - * @param map - * @param request - * @return - */ - @RequestMapping("/rfilterupdate") - @Menu(type = "report", subtype = "reportdesign") - public ModelAndView rfilterupdate(ModelMap map, HttpServletRequest request, @Valid ReportFilter f,@Valid String tbppy) { - String reportId = ""; - if (!StringUtils.isBlank(f.getId())) { - ReportFilter rf = reportFilterRepository.findByIdAndOrgi(f.getId(), super.getOrgi(request)); - if (rf != null) { - reportId = rf.getReportid(); - rf.setTitle(f.getTitle()); - rf.setCode(f.getCode()); - rf.setModeltype(f.getModeltype()); - rf.setConvalue(f.getConvalue()); - rf.setValuefiltertype(f.getValuefiltertype()); - rf.setComparetype(f.getComparetype()); - rf.setDefaultvalue(f.getDefaultvalue()); - rf.setStartvalue(f.getStartvalue()); - rf.setEndvalue(f.getEndvalue()); - rf.setFormatstr(f.getFormatstr()); - rf.setMustvalue(f.getMustvalue()); - - rf.setTableid(f.getTableid()); - rf.setFieldid(f.getFieldid()); - rf.setFktableid(f.getFktableid()); - rf.setFkfieldid(f.getFkfieldid()); - rf.setFilterfieldid(f.getFilterfieldid()); - - if(MainContext.FilterConValueType.AUTO.toString().equals(f.getConvalue()) && MainContext.FilterModelType.SIGSEL.toString().equals(f.getModeltype())) { - rf.setCascadeid(f.getCascadeid()); - rf.setTableproperty(null); - rf.setIsdic(f.isIsdic()); - rf.setDiccode(f.getDiccode()); - rf.setKeyfield(f.getKeyfield()); - rf.setValuefield(f.getValuefield()); - if(!StringUtils.isBlank(tbppy)) { - TableProperties t = new TableProperties(); - t.setId(tbppy); - rf.setTableproperty(t); - } - }else { - rf.setCascadeid(null); - rf.setTableproperty(null); - rf.setIsdic(false); - rf.setDiccode(""); - rf.setKeyfield(""); - rf.setValuefield(""); - } - reportFilterRepository.save(rf); - } - } - return request(super.createRequestPageTempletResponse( - "redirect:/apps/report/design/index.html?id=" + reportId)); - } - /** - * 编辑模型过滤器 - * - * @param map - * @param request - * @return - */ - @RequestMapping("/filteredit") - @Menu(type = "report", subtype = "reportdesign") - public ModelAndView filteredit(ModelMap map, HttpServletRequest request, @Valid String fid) { - map.addAttribute("sysdicList", sysDicRes.findByParentid("0")) ; - if (!StringUtils.isBlank(fid)) { - ReportFilter rf = reportFilterRepository.findByIdAndOrgi(fid, super.getOrgi(request)); - if(rf!=null) { - if (!StringUtils.isBlank(rf.getCubeid())) { - PublishedCube cube = publishedCubeRepository.findOne(rf.getCubeid()); - map.addAttribute("cube", cube); - List metadataTable = new ArrayList<>(); - for(CubeMetadata cm:cube.getCube().getMetadata()) { - if("0".equals(cm.getMtype())) { - map.addAttribute("table",cm.getTb()); - map.addAttribute("fieldList",cm.getTb().getTableproperty()); - } - metadataTable.add(cm.getTb()); - } - if(!StringUtils.isBlank(rf.getCascadeid())) { - ReportFilter rfcas = reportFilterRepository.findByIdAndOrgi(rf.getCascadeid(), super.getOrgi(request)); - if(rfcas!=null) { - map.put("fktableiddivList", tablePropertiesRes.findByDbtableid(rfcas.getFktableid())); - } - } - map.addAttribute("fktableList",metadataTable); - map.put("fktableidList", tablePropertiesRes.findByDbtableid(rf.getFktableid())); - } - ReportModel model = this.getModel(rf.getModelid(), super.getOrgi(request)); - map.addAttribute("reportModel", model); - } - map.addAttribute("reportFilter", rf); - } - return request(super.createRequestPageTempletResponse("/apps/business/report/design/modeldesign/filteredit")); - } - /** - * 编辑过滤器 - * - * @param map - * @param request - * @return - */ - @RequestMapping("/filterupdate") - @Menu(type = "report", subtype = "reportdesign") - public ModelAndView filterupdate(ModelMap map, HttpServletRequest request, @Valid ReportFilter f,@Valid String tbppy) { - String modelId = ""; - if (!StringUtils.isBlank(f.getId())) { - ReportFilter rf = reportFilterRepository.findByIdAndOrgi(f.getId(), super.getOrgi(request)); - if (rf != null) { - modelId = rf.getModelid(); - rf.setTitle(f.getTitle()); - rf.setCode(f.getCode()); - rf.setModeltype(f.getModeltype()); - rf.setConvalue(f.getConvalue()); - rf.setValuefiltertype(f.getValuefiltertype()); - rf.setComparetype(f.getComparetype()); - rf.setDefaultvalue(f.getDefaultvalue()); - rf.setStartvalue(f.getStartvalue()); - rf.setEndvalue(f.getEndvalue()); - rf.setFormatstr(f.getFormatstr()); - rf.setMustvalue(f.getMustvalue()); - - rf.setTableid(f.getTableid()); - rf.setFieldid(f.getFieldid()); - rf.setFktableid(f.getFktableid()); - rf.setFkfieldid(f.getFkfieldid()); - rf.setFilterfieldid(f.getFilterfieldid()); - - if(MainContext.FilterConValueType.AUTO.toString().equals(f.getConvalue()) && MainContext.FilterModelType.SIGSEL.toString().equals(f.getModeltype())) { - rf.setCascadeid(f.getCascadeid()); - rf.setTableproperty(null); - rf.setIsdic(f.isIsdic()); - rf.setDiccode(f.getDiccode()); - rf.setKeyfield(f.getKeyfield()); - rf.setValuefield(f.getValuefield()); - if(!StringUtils.isBlank(tbppy)) { - TableProperties t = new TableProperties(); - t.setId(tbppy); - rf.setTableproperty(t); - } - }else { - rf.setCascadeid(null); - rf.setTableproperty(null); - rf.setIsdic(false); - rf.setDiccode(""); - rf.setKeyfield(""); - rf.setValuefield(""); - } - reportFilterRepository.save(rf); - } - } - return request(super.createRequestPageTempletResponse( - "redirect:/apps/report/design/modeldesign.html?id=" + modelId + "&tabid=filter")); - } - @RequestMapping("/fktableid") - @Menu(type = "report" , subtype = "reportdesign" , admin= true) - public ModelAndView fktableid(ModelMap map , HttpServletRequest request , @Valid String fid,@Valid String fkId) { - if (!StringUtils.isBlank(fid)) { - ReportFilter rf = reportFilterRepository.findByIdAndOrgi(fid, super.getOrgi(request)); - if(rf!=null) { - if(!StringUtils.isBlank(fkId)) { - ReportFilter rfcas = reportFilterRepository.findByIdAndOrgi(fkId, super.getOrgi(request)); - if(rfcas!=null) { - map.put("fktableiddivList", tablePropertiesRes.findByDbtableid(rfcas.getFktableid())); - } - } - } - map.addAttribute("reportFilter", rf); - } - return request(super.createRequestPageTempletResponse("/apps/business/report/design/modeldesign/fktableiddiv")); - } - /** - * 编辑过滤器 - * - * @param map - * @param request - * @return - */ - @RequestMapping("/filterdel") - @Menu(type = "report", subtype = "reportdesign") - public ModelAndView filterdel(ModelMap map, HttpServletRequest request, @Valid String id) { - String modelId = ""; - if (!StringUtils.isBlank(id)) { - ReportFilter rf = reportFilterRepository.findByIdAndOrgi(id, super.getOrgi(request)); - if (rf != null) { - modelId = rf.getModelid(); - reportFilterRepository.delete(rf); - } - } - return request(super.createRequestPageTempletResponse( - "redirect:/apps/report/design/modeldesign.html?id=" + modelId + "&tabid=filter")); - } - /** - * 编辑过滤器 - * - * @param map - * @param request - * @return - */ - @RequestMapping("/rfilterdel") - @Menu(type = "report", subtype = "reportdesign") - public ModelAndView rfilterdel(ModelMap map, HttpServletRequest request, @Valid String id) { - String reportId = ""; - if (!StringUtils.isBlank(id)) { - ReportFilter rf = reportFilterRepository.findByIdAndOrgi(id, super.getOrgi(request)); - if (rf != null) { - reportId = rf.getReportid(); - reportFilterRepository.delete(rf); - } - } - return request(super.createRequestPageTempletResponse( - "redirect:/apps/report/design/index.html?id=" + reportId)); - } - /** - * 排序 - * - * @param map - * @param request - * @return - */ - @RequestMapping("/sort") - @Menu(type = "report", subtype = "reportdesign") - public ModelAndView sort(ModelMap map, HttpServletRequest request,@Valid String modelId,@Valid String type, @Valid String[] sort, @Valid String[] colsort, @Valid String[] rowsort) { - String tabid = "data"; - if (!StringUtils.isBlank(type)) { - if("dim".equals(type) || "measure".equals(type)) { - if(sort!=null && sort.length > 0 ) { - int index = 1; - for(String id:sort) { - ColumnProperties col = columnPropertiesRepository.findByIdAndOrgi(id,super.getOrgi(request)); - if(col!=null) { - col.setSortindex(index); - columnPropertiesRepository.save(col); - index++; - } - } - } - if(colsort!=null && colsort.length > 0 ) { - int index = 1; - for(String id:colsort) { - ColumnProperties col = columnPropertiesRepository.findByIdAndOrgi(id,super.getOrgi(request)); - if(col!=null) { - col.setSortindex(index); - col.setCur("cfield"); - columnPropertiesRepository.save(col); - index++; - } - } - } - if(rowsort!=null && rowsort.length > 0 ) { - int index = 1; - for(String id:rowsort) { - ColumnProperties col = columnPropertiesRepository.findByIdAndOrgi(id,super.getOrgi(request)); - if(col!=null) { - col.setSortindex(index); - col.setCur("field"); - columnPropertiesRepository.save(col); - index++; - } - } - } - }else { - tabid = "filter"; - if(sort!=null && sort.length > 0 ) { - int index = 1; - for(String id:sort) { - ReportFilter rf = reportFilterRepository.findByIdAndOrgi(id,super.getOrgi(request)); - if(rf!=null) { - rf.setSortindex(index); - reportFilterRepository.save(rf); - index++; - } - } - } - } - } - return request(super.createRequestPageTempletResponse( - "redirect:/apps/report/design/modeldesign.html?id=" + modelId + "&tabid="+tabid)); - } - - /** - * 移除维度或指标 - * - * @param map - * @param request - * @return - */ - @RequestMapping("/columndel") - @Menu(type = "report", subtype = "reportdesign") - public ModelAndView columndel(ModelMap map, HttpServletRequest request, @Valid String id) { - String modelId = ""; - if (!StringUtils.isBlank(id)) { - ColumnProperties col = columnPropertiesRepository.findByIdAndOrgi(id, super.getOrgi(request)); - if (col != null) { - modelId = col.getModelid(); - columnPropertiesRepository.delete(col); - } - } - return request(super.createRequestPageTempletResponse( - "redirect:/apps/report/design/modeldesign.html?id=" + modelId + "&tabid=data")); - } - - /** - * 修改指标 - * - * @param map - * @param request - * @return - */ - @RequestMapping("/columnedit") - @Menu(type = "report", subtype = "reportdesign") - public ModelAndView columnedit(ModelMap map, HttpServletRequest request, @Valid String id) { - if (!StringUtils.isBlank(id)) { - ColumnProperties col = columnPropertiesRepository.findByIdAndOrgi(id, super.getOrgi(request)); - if (col != null) { - map.put("col", col) ; - } - } - return request(super.createRequestPageTempletResponse("/apps/business/report/design/modeldesign/measureedit")); - } - - /** - * 保存指标 - * - * @param map - * @param request - * @return - */ - @RequestMapping("/columnupdate") - @Menu(type = "report", subtype = "reportdesign") - public ModelAndView columnupdte(ModelMap map, HttpServletRequest request, @Valid String id,@Valid String title, @Valid String mid) { - if (!StringUtils.isBlank(id) && !StringUtils.isBlank(title)) { - ColumnProperties col = columnPropertiesRepository.findByIdAndOrgi(id, super.getOrgi(request)); - if (col != null) { - col.setTitle(title); - columnPropertiesRepository.save(col) ; - } - } - return request(super.createRequestPageTempletResponse( - "redirect:/apps/report/design/modeldesign.html?id=" + mid + "&tabid=data")); - } - - @RequestMapping("/changetpl") - @Menu(type = "report", subtype = "reportdesign") - public ModelAndView changetpl(ModelMap map, HttpServletRequest request, @Valid String mid, @Valid String tplid) throws Exception { - ReportModel model = this.getModel(mid, super.getOrgi(request)); - if (!StringUtils.isBlank(tplid)) { - model.setTempletid(tplid); - Template tp = templateRes.findByIdAndOrgi(tplid, super.getOrgi(request)); - ChartProperties oldChartppy = model.getChartProperties(); - oldChartppy.setChartype(tp.getCharttype()); - Base64 base64 = new Base64(); - model.setChartcontent(base64.encodeToString(MainUtils.toBytes(oldChartppy))) ; - reportModelRes.save(model); - } - return request(super.createRequestPageTempletResponse( - "redirect:/apps/report/design/modeldesign.html?id=" + model.getId() + "&tabid=data")); - } - - @RequestMapping("/changechartppy") - @Menu(type = "report", subtype = "reportdesign") - public ModelAndView changechartppy(ModelMap map,HttpServletRequest request, @Valid ReportModel reportModel, @Valid ChartProperties chartProperties, HashMap semap) throws Exception { - ReportModel model = this.getModel(reportModel.getId(), super.getOrgi(request)); - if (null!=model) { - model.setExchangerw(reportModel.isExchangerw()); - model.setIsloadfulldata("true".equals(reportModel.getIsloadfulldata())?"true":"false"); - model.setPagesize(reportModel.getPagesize()); - ChartProperties oldChartppy = model.getChartProperties(); - oldChartppy = oldChartppy==null? new ChartProperties():oldChartppy; - oldChartppy.setLegen(chartProperties.isLegen()); - oldChartppy.setLegenalign(chartProperties.getLegenalign()); - oldChartppy.setDataview(chartProperties.isDataview()); - oldChartppy.setFormat(StringUtils.isBlank(chartProperties.getFormat())?"val":chartProperties.getFormat()); - Base64 base64 = new Base64(); - model.setChartcontent(base64.encodeToString(MainUtils.toBytes(oldChartppy))) ; - reportModelRes.save(model); - } - map.addAttribute("eltemplet", templateRes.findByIdAndOrgi(model.getTempletid(), super.getOrgi(request))); - map.addAttribute("element", model); - map.addAttribute("reportModel", model); - if (model != null && !StringUtils.isBlank(model.getPublishedcubeid())) { - PublishedCube cube = publishedCubeRepository.findOne(model.getPublishedcubeid()); - map.addAttribute("cube", cube); - if (!model.getMeasures().isEmpty()) { - map.addAttribute("reportData",reportCubeService.getReportData(model, cube.getCube(), request, true, semap)); - } - } - return request(super.createRequestPageTempletResponse("/apps/business/report/design/elementajax")); - } - - /** - * 组件设计 - * - * @param map - * @param request - * @param id - * @return - * @throws Exception - */ - @RequestMapping("/filtervalchange") - @Menu(type = "report", subtype = "reportdesign") - public ModelAndView filtervalchange(ModelMap map, HttpServletRequest request, @Valid String id, @Valid String fid,@Valid String publishedid) - throws Exception { - if(StringUtils.isBlank(publishedid)) { - ReportFilter filter = reportFilterRepository.findByIdAndOrgi(fid, super.getOrgi(request)); - if(filter!=null) { - if("report".equals(filter.getFiltertype())) { - ReportModel model = new ReportModel(); - List reportFilterList = reportFilterRepository.findByReportidAndFiltertypeAndOrgi(filter.getReportid(), "report", super.getOrgi(request)); - model.setFilters(reportFilterList); - map.addAttribute("filter", reportCubeService.processFilter(model, filter,null, request)); - }else { - ReportModel model = this.getModel(id, super.getOrgi(request)); - if (model!=null && !StringUtils.isBlank(fid) && !StringUtils.isBlank(model.getPublishedcubeid())) { - PublishedCube cube = publishedCubeRepository.findOne(model.getPublishedcubeid()); - map.addAttribute("filter", reportCubeService.processFilter(model, filter, cube.getCube(), request)); - } - } - } - }else { - PublishedReport publishedReport = publishedReportRes.findById(publishedid); - if(publishedReport!=null) { - map.addAttribute("publishedReport", publishedReport); - ReportFilter filter = null; - for(ReportFilter f : publishedReport.getReport().getReportFilters()) { - if(!StringUtils.isBlank(fid) && f.getId().equals(fid)) { - filter = f; - break; - } - } - ReportModel model = null; - for(ReportModel rm:publishedReport.getReport().getReportModels()) { - if(id.equals(rm.getId())) { - model = rm; - } - for(ReportFilter f:rm.getFilters()) { - if(!StringUtils.isBlank(fid) && f.getId().equals(fid)) { - filter = f; - break; - } - } - } - if(filter!=null) { - if("report".equals(filter.getFiltertype())) { - ReportModel modelr = new ReportModel(); - List reportFilterList = publishedReport.getReport().getReportFilters(); - modelr.setFilters(reportFilterList); - map.addAttribute("filter", reportCubeService.processFilter(modelr, filter,null, request)); - }else { - if (model!=null && !StringUtils.isBlank(fid) && !StringUtils.isBlank(model.getPublishedcubeid())) { - PublishedCube cube = publishedCubeRepository.findOne(model.getPublishedcubeid()); - map.addAttribute("filter", reportCubeService.processFilter(model, filter, cube.getCube(), request)); - } - } - } - } - } - - return request(super.createRequestPageTempletResponse("/apps/business/report/design/modeldesign/filter")); - } - @RequestMapping("/editmodelname") - @Menu(type = "report", subtype = "reportdesign") - public ModelAndView editmodelname(ModelMap map,HttpServletRequest request, @Valid String id, @Valid String name) { - map.addAttribute("id", id); - map.addAttribute("name", name); - return request(super.createRequestPageTempletResponse( - "/apps/business/report/design/modeldesign/editmodelname")); - } - @RequestMapping("/updatemodelname") - @Menu(type = "report", subtype = "reportdesign") - public ModelAndView updatemodelname(ModelMap map,HttpServletRequest request,@Valid String name, @Valid String id) { - ReportModel model = this.getModel(id, super.getOrgi(request)); - if(!StringUtils.isBlank(name)) { - model.setName(name); - reportModelRes.save(model); - } - return request(super.createRequestPageTempletResponse( - "redirect:/apps/report/design/modeldesign.html?id=" + model.getId() + "&tabid=data")); - } - /** - * 报表发布页面加载 - * @param request - * @param cubeid - * @return - * @throws Exception - */ - @RequestMapping("/reportpublish") - @Menu(type = "report" , subtype = "reportdesign" ) - public ModelAndView reportpublish(ModelMap map ,HttpServletRequest request , @Valid String reportid) throws Exception{ - map.put("reportid", reportid); - return request(super.createRequestPageTempletResponse("/apps/business/report/reportpublish")); - } - - /** - * 报表发布 - * @param request - * @param reportid - * @return - * @throws Exception - */ - @RequestMapping("/reportpublished") - @Menu(type = "report" , subtype = "reportdesign" ) - public ModelAndView reportpublished(ModelMap map ,HttpServletRequest request , @Valid String reportid,@Valid String isRecover) throws Exception{ - User user = super.getUser(request); - if(!StringUtils.isBlank(reportid)) { - Report report = reportRes.findByIdAndOrgi(reportid, super.getOrgi(request)); - List reportModels = reportModelRes.findByOrgiAndReportid(super.getOrgi(request), reportid); - - for(ReportModel r:reportModels){ - getModel(r.getId(), super.getOrgi(request)); - } - report.setReportModels(reportModels); - List reportFilters = reportCubeService.fillReportFilterData(reportFilterRepository.findByReportidAndFiltertypeAndOrgi(reportid, "report", super.getOrgi(request)),request); - report.setReportFilters(reportFilters); - PublishedReport publishedReport = new PublishedReport(); - MainUtils.copyProperties(report, publishedReport, ""); - publishedReport.setId(null); - Base64 base64 = new Base64(); - publishedReport.setReportcontent(base64.encodeToString(MainUtils.toBytes(report))) ; - publishedReport.setDataid(reportid); - publishedReport.setCreatetime(new Date()); - publishedReport.setCreater(user.getId()); - List pbReportList = publishedReportRes.findByOrgiAndDataidOrderByDataversionDesc(super.getOrgi(request), reportid); - if(!pbReportList.isEmpty()){ - int maxVersion = pbReportList.get(0).getDataversion() ; - if("yes".equals(isRecover)){ - publishedReport.setId(pbReportList.get(0).getId()) ; - publishedReport.setDataversion(pbReportList.get(0).getDataversion()); - publishedReportRes.save(publishedReport); - }else if("no".equals(isRecover)){ - publishedReport.setDataversion(maxVersion+1) ; - publishedReportRes.save(publishedReport); - }else{ - publishedReportRes.delete(pbReportList); - publishedReport.setDataversion(1) ; - publishedReportRes.save(publishedReport); - } - }else{ - publishedReport.setDataversion(1) ; - publishedReportRes.save(publishedReport); - } - return request(super.createRequestPageTempletResponse("redirect:/apps/report/index.html?dicid="+publishedReport.getDicid())); - } - return request(super.createRequestPageTempletResponse("redirect:/apps/report/index.html")); - } -} \ No newline at end of file +/* + * Copyright (C) 2017 优客服-多渠道客服系统 + * Modifications copyright (C) 2018-2019 Chatopera Inc, + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.chatopera.cc.controller.apps.report; + +import com.chatopera.cc.basic.Constants; +import com.chatopera.cc.basic.MainContext; +import com.chatopera.cc.basic.MainUtils; +import com.chatopera.cc.controller.Handler; +import com.chatopera.cc.model.*; +import com.chatopera.cc.persistence.repository.*; +import com.chatopera.cc.util.Menu; +import com.chatopera.cc.util.bi.ReportData; +import lombok.RequiredArgsConstructor; +import org.apache.commons.codec.binary.Base64; +import org.apache.commons.lang.exception.ExceptionUtils; +import org.apache.commons.lang3.StringUtils; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.lang.NonNull; +import org.springframework.stereotype.Controller; +import org.springframework.ui.ModelMap; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.servlet.ModelAndView; + +import javax.servlet.http.HttpServletRequest; +import javax.validation.Valid; +import java.util.*; + +@Controller +@RequestMapping("/apps/report/design") +@RequiredArgsConstructor +public class ReportDesignController extends Handler { + + @NonNull + private final TemplateRepository templateRes; + @NonNull + private final ReportRepository reportRes; + @NonNull + private final ReportModelRepository reportModelRes; + @NonNull + private final PublishedCubeRepository publishedCubeRepository; + @NonNull + private final ColumnPropertiesRepository columnPropertiesRepository; + @NonNull + private final ReportFilterRepository reportFilterRepository; + @NonNull + private final ReportCubeService reportCubeService; + @NonNull + private final TablePropertiesRepository tablePropertiesRes; + @NonNull + private final PublishedReportRepository publishedReportRes; + @NonNull + private final SysDicRepository sysDicRes; + @NonNull + private final MetadataRepository metadataRes; + @Value("${web.upload-path}") + private String path; + @Value("${uk.im.server.port}") + private Integer port; + + @RequestMapping("/index") + @Menu(type = "report", subtype = "reportdesign") + public ModelAndView index(ModelMap map, HttpServletRequest request, @Valid String q, @Valid String id) throws Exception { + List tpDicList = Dict.getInstance().getDic(Constants.CSKEFU_SYSTEM_DIC); + for (SysDic sysDic : tpDicList) { + if (sysDic.getCode().equals("layout")) { + map.addAttribute("layoutList", + templateRes.findByTemplettypeAndOrgi(sysDic.getId(), super.getOrgi(request))); + } else if (sysDic.getCode().equals("report")) { + map.addAttribute("reportList", + templateRes.findByTemplettypeAndOrgi(sysDic.getId(), super.getOrgi(request))); + } else if (sysDic.getCode().equals("filter")) { + map.addAttribute("filterList", + templateRes.findByTemplettypeAndOrgi(sysDic.getId(), super.getOrgi(request))); + } + } + + if (!StringUtils.isBlank(id)) { + map.addAttribute("report", reportRes.findByIdAndOrgi(id, super.getOrgi(request))); + map.addAttribute("reportModels", reportModelRes.findByOrgiAndReportid(super.getOrgi(request), id)); + + List listFilters = reportFilterRepository.findByReportidAndFiltertypeAndOrgi(id, "report", super.getOrgi(request)); + if (!listFilters.isEmpty()) { + Map filterMap = new HashMap(); + for (ReportFilter rf : listFilters) { + filterMap.put(rf.getId(), rf); + } + for (ReportFilter rf : listFilters) { + if (!StringUtils.isBlank(rf.getCascadeid())) { + rf.setChildFilter(filterMap.get(rf.getCascadeid())); + } + } + } + map.addAttribute("reportFilters", reportCubeService.fillReportFilterData(listFilters, request)); + } + return request(super.createRequestPageTempletResponse("/apps/business/report/design/index")); + } + + /** + * 请求 报表的模板组件, 请求的时候,生成个报表组件,报表组件 需要存放在列的对应关系中 + * + * @param map + * @param request + * @param template + * @param id + * @return + * @throws Exception + */ + @RequestMapping("/rtpl") + @Menu(type = "report", subtype = "reportdesign") + public ModelAndView rtpl(ModelMap map, HttpServletRequest request, @Valid String tplname, @Valid String template, + @Valid String colindex, @Valid String id, @Valid String parentid, @Valid String mid) throws Exception { + Template tp = templateRes.findByIdAndOrgi(template, super.getOrgi(request)); + map.addAttribute("eltemplet", tp); + if (!StringUtils.isBlank(parentid)) { + ReportModel model = new ReportModel(); + model.setOrgi(super.getOrgi(request)); + model.setCreatetime(new Date()); + model.setReportid(id); + model.setParentid(parentid); + model.setName(tplname); + if (!StringUtils.isBlank(colindex) && colindex.matches("[\\d]{1,}")) { + model.setColindex(Integer.parseInt(colindex)); + } else { + model.setColindex(1); + } + ChartProperties chartProperties = new ChartProperties(); + chartProperties.setChartype(tp.getCharttype()); + Base64 base64 = new Base64(); + model.setChartcontent(base64.encodeToString(MainUtils.toBytes(chartProperties))); + model.setTempletid(template); + model.setMid(mid); + + reportModelRes.save(model); + map.addAttribute("element", model); + } + return request(super.createRequestPageTempletResponse("/apps/business/report/design/element")); + } + + /** + * 请求 报表的模板组件, 请求的时候,生成个报表组件,报表组件 需要存放在列的对应关系中 + */ + @RequestMapping("/element") + @Menu(type = "report", subtype = "reportdesign") + public ModelAndView element(ModelMap map, HttpServletRequest request, @Valid String colindex, @Valid String id, + @Valid String parentid, @Valid String mid) { + + if (!StringUtils.isBlank(id) && !StringUtils.isBlank(parentid)) { + ReportModel model = reportModelRes.findByIdAndOrgi(id, super.getOrgi(request)); + if (model != null) { + model.setParentid(parentid); + if (!StringUtils.isBlank(colindex) && colindex.matches("[\\d]{1,}")) { + model.setColindex(Integer.parseInt(colindex)); + } else { + model.setColindex(1); + } + reportModelRes.save(model); + } + } + return request(super.createRequestPageTempletResponse("/public/success")); + } + + /** + * 请求 布局的模板组件 , 请求的时候,生成一个布局记录,布局记录分两个部分,一个是行,一个是列 ,一次请求,创建一条行记录(ROW)和多个列记录(COL) + * 行记录和列记录都存放到 ES中 + * + * @param map + * @param request + * @param template + * @param id + * @return + */ + @RequestMapping("/ltpl") + @Menu(type = "report", subtype = "reportdesign") + public ModelAndView ltpl(ModelMap map, HttpServletRequest request, @Valid String template, @Valid String id, + @Valid String mid, @Valid String colspan) { + map.addAttribute("templet", templateRes.findByIdAndOrgi(template, super.getOrgi(request))); + ReportModel model = new ReportModel(); + model.setOrgi(super.getOrgi(request)); + model.setCreatetime(new Date()); + model.setReportid(id); + model.setParentid(id); + + if (!StringUtils.isBlank(colspan) && colspan.matches("[\\d]{1,}")) { + model.setColspan(Integer.parseInt(colspan)); + } else { + model.setColspan(4); + } + model.setTempletid(template); + model.setMid(mid); + + reportModelRes.save(model); + map.addAttribute("model", model); + + return request(super.createRequestPageTempletResponse("/apps/business/report/design/layout")); + } + + /** + * 请求 过滤器的模板组件, 请求的时候,生成个过滤器组件 + * + * @param map + * @param request + * @param template + * @param id + * @return + */ + @RequestMapping("/ftpl") + @Menu(type = "report", subtype = "reportdesign") + public ModelAndView ftpl(ModelMap map, HttpServletRequest request, @Valid String tplname, @Valid String template, + @Valid String colindex, @Valid String id, @Valid String parentid, @Valid String mid) { + Template t = templateRes.findByIdAndOrgi(template, super.getOrgi(request)); + map.addAttribute("eltemplet", t); + if (!StringUtils.isBlank(parentid)) { + ReportFilter filter = new ReportFilter(); + filter.setCode(MainUtils.genID()); + filter.setReportid(id); + filter.setOrgi(super.getOrgi(request)); + filter.setCreatetime(new Date()); + filter.setName(t.getName()); + filter.setDataname(t.getName()); + filter.setTitle(t.getName()); + filter.setFiltertype("report"); + filter.setFuntype("filter"); + filter.setFiltertemplet(template); + filter.setModelid(mid); + filter.setModeltype(t.getCode()); + + filter.setConvalue(MainContext.FilterConValueType.INPUT.toString()); + filter.setValuefiltertype(MainContext.FilterValuefilterType.COMPARE.toString()); + filter.setComparetype(MainContext.FilterCompType.EQUAL.toString()); + filter.setFormatstr("yyyy-MM-dd"); + reportFilterRepository.save(filter); + map.addAttribute("filter", filter); + } + return request(super.createRequestPageTempletResponse("/apps/business/report/design/filter")); + } + + /** + * 删除模板组件 + * + * @param map + * @param request + * @param id + * @return + */ + @RequestMapping("/modeldelete") + @Menu(type = "report", subtype = "reportdesign") + public ModelAndView modeldelete(ModelMap map, HttpServletRequest request, @Valid String id) { + ReportModel model = reportModelRes.findByIdAndOrgi(id, super.getOrgi(request)); + if (model != null) { + List childsList = reportModelRes.findByParentidAndOrgi(model.getId(), super.getOrgi(request)); + if (!childsList.isEmpty()) { + reportModelRes.deleteAll(childsList); + } + reportModelRes.delete(model); + } + return request(super.createRequestPageTempletResponse("/public/success")); + } + + /** + * 组件设计 + * + * @param map + * @param request + * @param id + * @return + * @throws Exception + */ + @RequestMapping("/modeldesign") + @Menu(type = "report", subtype = "reportdesign") + public ModelAndView modeldesign(ModelMap map, HttpServletRequest request, @Valid String id, @Valid String tabid, HashMap semap) + throws Exception { + List tpDicList = Dict.getInstance().getDic(Constants.CSKEFU_SYSTEM_DIC); + for (SysDic sysDic : tpDicList) { + if (sysDic.getCode().equals("report")) { + map.addAttribute("reportList", + templateRes.findByTemplettypeAndOrgi(sysDic.getId(), super.getOrgi(request))); + } + } + + ReportModel model = this.getModel(id, super.getOrgi(request)); + map.addAttribute("reportModel", model); + map.addAttribute("element", model); + if (model != null && !StringUtils.isBlank(model.getPublishedcubeid())) { + PublishedCube cube = publishedCubeRepository.findById(model.getPublishedcubeid()); + map.addAttribute("cube", cube); + if (canGetReportData(model, cube.getCube())) { + ReportData reportData = null; + try { + reportData = reportCubeService.getReportData(model, cube.getCube(), request, true, semap); + map.addAttribute("reportData", reportData); + } catch (Exception ex) { + map.addAttribute("msg", (ExceptionUtils.getMessage(ex).replaceAll("\r\n", "") + ExceptionUtils.getRootCauseMessage(ex)).replaceAll("\"", "'")); + } + } + map.addAttribute("eltemplet", templateRes.findByIdAndOrgi(model.getTempletid(), super.getOrgi(request))); + } + map.addAttribute("tabid", tabid); + return request(super.createRequestPageTempletResponse("/apps/business/report/design/modeldesign")); + } + + private boolean canGetReportData(ReportModel model, Cube cube) { + return !model.getProperties().isEmpty() || !model.getColproperties().isEmpty() || !model.getMeasures().isEmpty(); + } + + private ReportModel getModel(String id, String orgi) { + ReportModel model = reportModelRes.findByIdAndOrgi(id, orgi); + if (model != null) { + model.setProperties( + columnPropertiesRepository.findByModelidAndCurOrderBySortindexAsc(model.getId(), "field")); + model.setColproperties( + columnPropertiesRepository.findByModelidAndCurOrderBySortindexAsc(model.getId(), "cfield")); + model.setMeasures( + columnPropertiesRepository.findByModelidAndCurOrderBySortindexAsc(model.getId(), "measure")); + List listFilters = reportFilterRepository.findByModelidOrderBySortindexAsc(model.getId()); + if (!listFilters.isEmpty()) { + for (ReportFilter rf : listFilters) { + if (!StringUtils.isBlank(rf.getCascadeid())) { + rf.setChildFilter(reportFilterRepository.findByIdAndOrgi(rf.getCascadeid(), orgi)); + } + } + } + model.setFilters(listFilters); + } + return model; + } + + /** + * 选择模型 + * + * @param request + * @return + * @throws Exception + */ + @RequestMapping("/dataset") + @Menu(type = "report", subtype = "reportdesign") + public ModelAndView dataset(ModelMap map, HttpServletRequest request, @Valid String mid, @Valid String cubeid) + throws Exception { + if (!StringUtils.isBlank(cubeid)) { + PublishedCube cube = publishedCubeRepository.findOne(cubeid); + map.put("cube", cube); + } + ReportModel model = this.getModel(mid, super.getOrgi(request)); + if (!StringUtils.isBlank(cubeid)) { + model.setPublishedcubeid(cubeid); + columnPropertiesRepository.deleteAll(model.getProperties()); + columnPropertiesRepository.deleteAll(model.getColproperties()); + columnPropertiesRepository.deleteAll(model.getMeasures()); + reportFilterRepository.deleteAll(model.getFilters()); + } + reportModelRes.save(model); + map.put("reportModel", model); + return request(super.createRequestPageTempletResponse( + "redirect:/apps/report/design/modeldesign.html?id=" + model.getId())); + } + + @RequestMapping("/adddata") + @Menu(type = "report", subtype = "reportdesign") + public ModelAndView dimensionadd(ModelMap map, HttpServletRequest request, @Valid String cubeid, @Valid String t, @Valid String dtype, + @Valid String mid, @Valid String dim, @Valid String tabid) { + ModelAndView view = request( + super.createRequestPageTempletResponse("/apps/business/report/design/modeldesign/add")); + if (!StringUtils.isBlank(cubeid)) { + PublishedCube cube = publishedCubeRepository.findOne(cubeid); + map.addAttribute("cube", cube); + } + map.addAttribute("t", t); + ReportModel model = reportModelRes.findByIdAndOrgi(mid, super.getOrgi(request)); + if (!StringUtils.isBlank(cubeid)) { + model.setPublishedcubeid(cubeid); + } + map.addAttribute("reportModel", model); + map.addAttribute("dim", dim); + map.addAttribute("tabid", tabid); + map.addAttribute("dtype", dtype); + return view; + } + + /** + * 添加过滤器 + * + * @param map + * @param request + * @return + */ + @RequestMapping("/filteradd") + @Menu(type = "report", subtype = "reportdesign") + public ModelAndView filteradd(ModelMap map, HttpServletRequest request, @Valid String cubeid, @Valid String dtype, + @Valid String mid) { + ModelAndView view = request( + super.createRequestPageTempletResponse("/apps/business/report/design/modeldesign/filteradd")); + if (!StringUtils.isBlank(cubeid)) { + PublishedCube cube = publishedCubeRepository.findOne(cubeid); + map.addAttribute("cube", cube); + List metadataTable = new ArrayList<>(); + for (CubeMetadata cm : cube.getCube().getMetadata()) { + if ("0".equals(cm.getMtype())) { + map.addAttribute("table", cm.getTb()); + map.addAttribute("fieldList", cm.getTb().getTableproperty()); + } + metadataTable.add(cm.getTb()); + } + map.addAttribute("fktableList", metadataTable); + } + map.addAttribute("sysdicList", sysDicRes.findByParentid("0")); + map.addAttribute("mid", mid); + map.addAttribute("dtype", dtype); + return view; + } + + /** + * 保存过滤器 + * + * @param map + * @param request + * @return + */ + @RequestMapping("/filtersave") + @Menu(type = "report", subtype = "reportdesign") + public ModelAndView filterupfiltersavedate(ModelMap map, HttpServletRequest request, @Valid ReportFilter f, @Valid String tbppy) { + String modelId = ""; + if (f != null) { + if (StringUtils.isBlank(f.getCode())) { + f.setCode(MainUtils.genID()); + } + f.setOrgi(super.getOrgi(request)); + f.setCreatetime(new Date()); + f.setName(f.getTitle()); + f.setDataname(f.getTitle()); + if (MainContext.FilterConValueType.AUTO.toString().equals(f.getConvalue()) && MainContext.FilterModelType.SIGSEL.toString().equals(f.getModeltype())) { + f.setCascadeid(f.getCascadeid()); + f.setTableproperty(null); + if (!StringUtils.isBlank(tbppy)) { + TableProperties t = new TableProperties(); + t.setId(tbppy); + f.setTableproperty(t); + } + } else { + f.setCascadeid(null); + f.setTableproperty(null); + } + modelId = f.getModelid(); + reportFilterRepository.save(f); + } + return request(super.createRequestPageTempletResponse( + "redirect:/apps/report/design/modeldesign.html?id=" + modelId + "&tabid=filter")); + } + + @RequestMapping("/gettableid") + @Menu(type = "report", subtype = "reportdesign") + public ModelAndView gettableid(ModelMap map, HttpServletRequest request, @Valid String tableid) { + if (!StringUtils.isBlank(tableid)) { + map.put("fktableidList", tablePropertiesRes.findByDbtableid(tableid)); + } + return request(super.createRequestPageTempletResponse("/apps/business/report/design/modeldesign/fktableid")); + } + + @RequestMapping("/values") + @Menu(type = "report", subtype = "reportdesign") + public ModelAndView values(ModelMap map, HttpServletRequest request, @Valid String mid, @Valid String dsid, + @Valid String t, @Valid String d, @Valid String dtype, @Valid String m, @Valid String f, @Valid String tabid) throws Exception { + ReportModel model = this.getModel(mid, super.getOrgi(request)); + if (!StringUtils.isBlank(dsid)) { + model.setPublishedcubeid(dsid); + } + PublishedCube cube = publishedCubeRepository.findOne(dsid); + + if (!StringUtils.isBlank(d)) { + boolean inlist = false; + ColumnProperties currCp = null; + if (cube != null && cube.getCube() != null && cube.getCube().getDimension().size() > 0) { + for (ColumnProperties level : model.getProperties()) { + if (level.getDataid().equals(d)) { + inlist = true; + currCp = level; + break; + } + } + for (ColumnProperties level : model.getColproperties()) { + if (level.getDataid().equals(d)) { + inlist = true; + currCp = level; + break; + } + } + if (!inlist) { + ColumnProperties col = new ColumnProperties(); + if (StringUtils.isBlank(dtype)) { + col.setCur("field"); // 数据结构字段 + } else { + col.setCur(dtype); + } + col.setId(MainUtils.genID()); + CubeLevel cubeLevel = null; + for (Dimension dim : cube.getCube().getDimension()) { + for (CubeLevel level : dim.getCubeLevel()) { + if (level.getId().equals(d)) { + cubeLevel = level; + break; + } + } + } + if (cubeLevel != null) { + col.setDataid(d); + col.setDataname(cubeLevel.getName()); + col.setColname(cubeLevel.getColumname()); + col.setTitle(cubeLevel.getName()); + } + col.setSortindex(("cfield".equals(dtype)) ? model.getColproperties().size() + 1 : model.getProperties().size() + 1); + col.setOrgi(super.getOrgi(request)); + col.setModelid(model.getId()); + columnPropertiesRepository.save(col); + } else { + if (!StringUtils.isBlank(dtype)) { + currCp.setCur(dtype); + currCp.setSortindex(("cfield".equals(dtype)) ? model.getColproperties().size() + 1 : model.getProperties().size() + 1); + columnPropertiesRepository.save(currCp); + } + } + } + } + if (!StringUtils.isBlank(m)) { + boolean inlist = false; + if (cube != null && cube.getCube() != null && cube.getCube().getMeasure().size() > 0) { + for (ColumnProperties measure : model.getMeasures()) { + if (measure.getDataid().equals(m)) { + inlist = true; + break; + } + } + if (!inlist) { + ColumnProperties col = new ColumnProperties(); + col.setCur("measure"); // 数据结构字段 + col.setId(MainUtils.genID()); + CubeMeasure cubeMeasure = null; + for (CubeMeasure measure : cube.getCube().getMeasure()) { + if (measure.getId().equals(m)) { + cubeMeasure = measure; + break; + } + } + if (cubeMeasure != null) { + col.setDataid(m); + col.setDataname(cubeMeasure.getName()); + col.setColname(cubeMeasure.getColumname()); + col.setTitle(cubeMeasure.getName()); + } + col.setSortindex(model.getMeasures().size() + 1); + col.setOrgi(super.getOrgi(request)); + col.setModelid(model.getId()); + model.getMeasures().add(col); + columnPropertiesRepository.save(col); + } + } + } + if (!StringUtils.isBlank(f)) { + boolean inlist = false; + if (cube != null && cube.getCube() != null && cube.getCube().getDimension().size() > 0) { + for (ReportFilter filter : model.getFilters()) { + if (filter.getDataid().equals(f)) { + inlist = true; + break; + } + } + if (!inlist) { + ReportFilter filter = new ReportFilter(); + filter.setId(MainUtils.genID()); + CubeLevel cubeLevel = null; + if (cube != null && cube.getCube() != null && cube.getCube().getDimension().size() > 0) { + for (Dimension dim : cube.getCube().getDimension()) { + for (CubeLevel level : dim.getCubeLevel()) { + if (level.getId().equals(f)) { + cubeLevel = level; + break; + } + } + } + if (cubeLevel != null) { + filter.setCubeid(cube.getId()); + filter.setDataid(cubeLevel.getId()); + filter.setDimid(cubeLevel.getDimid()); + filter.setLevel(cubeLevel); + filter.setDataname(cubeLevel.getName()); + filter.setTitle(cubeLevel.getName()); + filter.setModelid(mid); + + filter.setModeltype(MainContext.FilterModelType.TEXT.toString()); + filter.setConvalue(MainContext.FilterConValueType.INPUT.toString()); + filter.setValuefiltertype(MainContext.FilterValuefilterType.COMPARE.toString()); + filter.setComparetype(MainContext.FilterCompType.EQUAL.toString()); + + if ("select".equalsIgnoreCase(filter.getModeltype())) { + filter.setConvalue(MainContext.FilterConValueType.AUTO.toString()); + } + } + filter.setReportid(model.getReportid()); + filter.setSortindex(model.getFilters().size() + 1); + filter.setOrgi(super.getOrgi(request)); + model.getFilters().add(filter); + reportFilterRepository.save(filter); + } + } + } + } + return request(super.createRequestPageTempletResponse( + "redirect:/apps/report/design/modeldesign.html?id=" + model.getId() + "&tabid=" + tabid)); + } + + /** + * 异步 请求 报表的模板组件 + * + * @param map + * @param request + * @param id + * @return + * @throws Exception + */ + @RequestMapping("/getelement") + @Menu(type = "report", subtype = "reportdesign") + public ModelAndView getelement(ModelMap map, HttpServletRequest request, @Valid String id, @Valid String publishedid, HashMap semap) throws Exception { + if (!StringUtils.isBlank(id)) { + ReportModel model = this.getModel(id, super.getOrgi(request), publishedid); + if (model != null) { + map.addAttribute("eltemplet", MainUtils.getTemplate(model.getTempletid())); + } + map.addAttribute("element", model); + map.addAttribute("reportModel", model); + + if (model != null && !StringUtils.isBlank(model.getPublishedcubeid())) { + List cubeList = publishedCubeRepository.findByIdAndOrgi(model.getPublishedcubeid(), super.getOrgi(request)); + if (cubeList.size() > 0) { + PublishedCube cube = cubeList.get(0); + map.addAttribute("cube", cube); + if (canGetReportData(model, cube.getCube())) { + ReportData reportData = null; + try { + reportData = reportCubeService.getReportData(model, cube.getCube(), request, true, semap); + map.addAttribute("reportData", reportData); + } catch (Exception ex) { + map.addAttribute("msg", ex.getMessage()); + } + } + } + } + } + return request(super.createRequestPageTempletResponse("/apps/business/report/design/elementajax")); + } + + private ReportModel getModel(String id, String orgi, String publishedid) { + if (!StringUtils.isBlank(publishedid)) { + PublishedReport publishedReport = publishedReportRes.findById(publishedid); + if (publishedReport != null) { + if (publishedReport.getReport() != null && !publishedReport.getReport().getReportModels().isEmpty()) { + for (ReportModel rm : publishedReport.getReport().getReportModels()) { + if (rm.getId().equals(id)) { + return rm; + } + } + } + return this.getModel(id, orgi); + } else { + return this.getModel(id, orgi); + } + } else { + return this.getModel(id, orgi); + } + + } + + /** + * 编辑报表过滤器 + * + * @param map + * @param request + * @return + * @throws Exception + */ + @RequestMapping("/rfilteredit") + @Menu(type = "report", subtype = "reportdesign") + public ModelAndView rfilteredit(ModelMap map, HttpServletRequest request, @Valid String fid) throws Exception { + map.addAttribute("sysdicList", sysDicRes.findByParentid("0")); + if (!StringUtils.isBlank(fid)) { + ReportFilter rf = reportFilterRepository.findByIdAndOrgi(fid, super.getOrgi(request)); + if (rf != null) { + map.addAttribute("fktableList", metadataRes.findByOrgi(super.getOrgi(request))); + map.put("fktableidList", tablePropertiesRes.findByDbtableid(rf.getFktableid())); + if (!StringUtils.isBlank(rf.getCascadeid())) { + ReportFilter rfcas = reportFilterRepository.findByIdAndOrgi(rf.getCascadeid(), super.getOrgi(request)); + if (rfcas != null) { + map.put("fktableiddivList", tablePropertiesRes.findByDbtableid(rfcas.getFktableid())); + } + } + } + map.addAttribute("reportFilter", rf); + map.addAttribute("reportFilters", reportCubeService.fillReportFilterData(reportFilterRepository.findByReportidAndFiltertypeAndOrgi(rf.getReportid(), "report", super.getOrgi(request)), request)); + } + return request(super.createRequestPageTempletResponse("/apps/business/report/design/filteredit")); + } + + /** + * 编辑过滤器 + * + * @param map + * @param request + * @return + */ + @RequestMapping("/rfilterupdate") + @Menu(type = "report", subtype = "reportdesign") + public ModelAndView rfilterupdate(ModelMap map, HttpServletRequest request, @Valid ReportFilter f, @Valid String tbppy) { + String reportId = ""; + if (!StringUtils.isBlank(f.getId())) { + ReportFilter rf = reportFilterRepository.findByIdAndOrgi(f.getId(), super.getOrgi(request)); + if (rf != null) { + reportId = rf.getReportid(); + rf.setTitle(f.getTitle()); + rf.setCode(f.getCode()); + rf.setModeltype(f.getModeltype()); + rf.setConvalue(f.getConvalue()); + rf.setValuefiltertype(f.getValuefiltertype()); + rf.setComparetype(f.getComparetype()); + rf.setDefaultvalue(f.getDefaultvalue()); + rf.setStartvalue(f.getStartvalue()); + rf.setEndvalue(f.getEndvalue()); + rf.setFormatstr(f.getFormatstr()); + rf.setMustvalue(f.getMustvalue()); + + rf.setTableid(f.getTableid()); + rf.setFieldid(f.getFieldid()); + rf.setFktableid(f.getFktableid()); + rf.setFkfieldid(f.getFkfieldid()); + rf.setFilterfieldid(f.getFilterfieldid()); + + if (MainContext.FilterConValueType.AUTO.toString().equals(f.getConvalue()) && MainContext.FilterModelType.SIGSEL.toString().equals(f.getModeltype())) { + rf.setCascadeid(f.getCascadeid()); + rf.setTableproperty(null); + rf.setIsdic(f.isIsdic()); + rf.setDiccode(f.getDiccode()); + rf.setKeyfield(f.getKeyfield()); + rf.setValuefield(f.getValuefield()); + if (!StringUtils.isBlank(tbppy)) { + TableProperties t = new TableProperties(); + t.setId(tbppy); + rf.setTableproperty(t); + } + } else { + rf.setCascadeid(null); + rf.setTableproperty(null); + rf.setIsdic(false); + rf.setDiccode(""); + rf.setKeyfield(""); + rf.setValuefield(""); + } + reportFilterRepository.save(rf); + } + } + return request(super.createRequestPageTempletResponse( + "redirect:/apps/report/design/index.html?id=" + reportId)); + } + + /** + * 编辑模型过滤器 + * + * @param map + * @param request + * @return + */ + @RequestMapping("/filteredit") + @Menu(type = "report", subtype = "reportdesign") + public ModelAndView filteredit(ModelMap map, HttpServletRequest request, @Valid String fid) { + map.addAttribute("sysdicList", sysDicRes.findByParentid("0")); + if (!StringUtils.isBlank(fid)) { + ReportFilter rf = reportFilterRepository.findByIdAndOrgi(fid, super.getOrgi(request)); + if (rf != null) { + if (!StringUtils.isBlank(rf.getCubeid())) { + PublishedCube cube = publishedCubeRepository.findOne(rf.getCubeid()); + map.addAttribute("cube", cube); + List metadataTable = new ArrayList<>(); + for (CubeMetadata cm : cube.getCube().getMetadata()) { + if ("0".equals(cm.getMtype())) { + map.addAttribute("table", cm.getTb()); + map.addAttribute("fieldList", cm.getTb().getTableproperty()); + } + metadataTable.add(cm.getTb()); + } + if (!StringUtils.isBlank(rf.getCascadeid())) { + ReportFilter rfcas = reportFilterRepository.findByIdAndOrgi(rf.getCascadeid(), super.getOrgi(request)); + if (rfcas != null) { + map.put("fktableiddivList", tablePropertiesRes.findByDbtableid(rfcas.getFktableid())); + } + } + map.addAttribute("fktableList", metadataTable); + map.put("fktableidList", tablePropertiesRes.findByDbtableid(rf.getFktableid())); + } + ReportModel model = this.getModel(rf.getModelid(), super.getOrgi(request)); + map.addAttribute("reportModel", model); + } + map.addAttribute("reportFilter", rf); + } + return request(super.createRequestPageTempletResponse("/apps/business/report/design/modeldesign/filteredit")); + } + + /** + * 编辑过滤器 + * + * @param map + * @param request + * @return + */ + @RequestMapping("/filterupdate") + @Menu(type = "report", subtype = "reportdesign") + public ModelAndView filterupdate(ModelMap map, HttpServletRequest request, @Valid ReportFilter f, @Valid String tbppy) { + String modelId = ""; + if (!StringUtils.isBlank(f.getId())) { + ReportFilter rf = reportFilterRepository.findByIdAndOrgi(f.getId(), super.getOrgi(request)); + if (rf != null) { + modelId = rf.getModelid(); + rf.setTitle(f.getTitle()); + rf.setCode(f.getCode()); + rf.setModeltype(f.getModeltype()); + rf.setConvalue(f.getConvalue()); + rf.setValuefiltertype(f.getValuefiltertype()); + rf.setComparetype(f.getComparetype()); + rf.setDefaultvalue(f.getDefaultvalue()); + rf.setStartvalue(f.getStartvalue()); + rf.setEndvalue(f.getEndvalue()); + rf.setFormatstr(f.getFormatstr()); + rf.setMustvalue(f.getMustvalue()); + + rf.setTableid(f.getTableid()); + rf.setFieldid(f.getFieldid()); + rf.setFktableid(f.getFktableid()); + rf.setFkfieldid(f.getFkfieldid()); + rf.setFilterfieldid(f.getFilterfieldid()); + + if (MainContext.FilterConValueType.AUTO.toString().equals(f.getConvalue()) && MainContext.FilterModelType.SIGSEL.toString().equals(f.getModeltype())) { + rf.setCascadeid(f.getCascadeid()); + rf.setTableproperty(null); + rf.setIsdic(f.isIsdic()); + rf.setDiccode(f.getDiccode()); + rf.setKeyfield(f.getKeyfield()); + rf.setValuefield(f.getValuefield()); + if (!StringUtils.isBlank(tbppy)) { + TableProperties t = new TableProperties(); + t.setId(tbppy); + rf.setTableproperty(t); + } + } else { + rf.setCascadeid(null); + rf.setTableproperty(null); + rf.setIsdic(false); + rf.setDiccode(""); + rf.setKeyfield(""); + rf.setValuefield(""); + } + reportFilterRepository.save(rf); + } + } + return request(super.createRequestPageTempletResponse( + "redirect:/apps/report/design/modeldesign.html?id=" + modelId + "&tabid=filter")); + } + + @RequestMapping("/fktableid") + @Menu(type = "report", subtype = "reportdesign", admin = true) + public ModelAndView fktableid(ModelMap map, HttpServletRequest request, @Valid String fid, @Valid String fkId) { + if (!StringUtils.isBlank(fid)) { + ReportFilter rf = reportFilterRepository.findByIdAndOrgi(fid, super.getOrgi(request)); + if (rf != null) { + if (!StringUtils.isBlank(fkId)) { + ReportFilter rfcas = reportFilterRepository.findByIdAndOrgi(fkId, super.getOrgi(request)); + if (rfcas != null) { + map.put("fktableiddivList", tablePropertiesRes.findByDbtableid(rfcas.getFktableid())); + } + } + } + map.addAttribute("reportFilter", rf); + } + return request(super.createRequestPageTempletResponse("/apps/business/report/design/modeldesign/fktableiddiv")); + } + + /** + * 编辑过滤器 + * + * @param map + * @param request + * @return + */ + @RequestMapping("/filterdel") + @Menu(type = "report", subtype = "reportdesign") + public ModelAndView filterdel(ModelMap map, HttpServletRequest request, @Valid String id) { + String modelId = ""; + if (!StringUtils.isBlank(id)) { + ReportFilter rf = reportFilterRepository.findByIdAndOrgi(id, super.getOrgi(request)); + if (rf != null) { + modelId = rf.getModelid(); + reportFilterRepository.delete(rf); + } + } + return request(super.createRequestPageTempletResponse( + "redirect:/apps/report/design/modeldesign.html?id=" + modelId + "&tabid=filter")); + } + + /** + * 编辑过滤器 + * + * @param map + * @param request + * @return + */ + @RequestMapping("/rfilterdel") + @Menu(type = "report", subtype = "reportdesign") + public ModelAndView rfilterdel(ModelMap map, HttpServletRequest request, @Valid String id) { + String reportId = ""; + if (!StringUtils.isBlank(id)) { + ReportFilter rf = reportFilterRepository.findByIdAndOrgi(id, super.getOrgi(request)); + if (rf != null) { + reportId = rf.getReportid(); + reportFilterRepository.delete(rf); + } + } + return request(super.createRequestPageTempletResponse( + "redirect:/apps/report/design/index.html?id=" + reportId)); + } + + /** + * 排序 + * + * @param map + * @param request + * @return + */ + @RequestMapping("/sort") + @Menu(type = "report", subtype = "reportdesign") + public ModelAndView sort(ModelMap map, HttpServletRequest request, @Valid String modelId, @Valid String type, @Valid String[] sort, @Valid String[] colsort, @Valid String[] rowsort) { + String tabid = "data"; + if (!StringUtils.isBlank(type)) { + if ("dim".equals(type) || "measure".equals(type)) { + if (sort != null && sort.length > 0) { + int index = 1; + for (String id : sort) { + ColumnProperties col = columnPropertiesRepository.findByIdAndOrgi(id, super.getOrgi(request)); + if (col != null) { + col.setSortindex(index); + columnPropertiesRepository.save(col); + index++; + } + } + } + if (colsort != null && colsort.length > 0) { + int index = 1; + for (String id : colsort) { + ColumnProperties col = columnPropertiesRepository.findByIdAndOrgi(id, super.getOrgi(request)); + if (col != null) { + col.setSortindex(index); + col.setCur("cfield"); + columnPropertiesRepository.save(col); + index++; + } + } + } + if (rowsort != null && rowsort.length > 0) { + int index = 1; + for (String id : rowsort) { + ColumnProperties col = columnPropertiesRepository.findByIdAndOrgi(id, super.getOrgi(request)); + if (col != null) { + col.setSortindex(index); + col.setCur("field"); + columnPropertiesRepository.save(col); + index++; + } + } + } + } else { + tabid = "filter"; + if (sort != null && sort.length > 0) { + int index = 1; + for (String id : sort) { + ReportFilter rf = reportFilterRepository.findByIdAndOrgi(id, super.getOrgi(request)); + if (rf != null) { + rf.setSortindex(index); + reportFilterRepository.save(rf); + index++; + } + } + } + } + } + return request(super.createRequestPageTempletResponse( + "redirect:/apps/report/design/modeldesign.html?id=" + modelId + "&tabid=" + tabid)); + } + + /** + * 移除维度或指标 + * + * @param map + * @param request + * @return + */ + @RequestMapping("/columndel") + @Menu(type = "report", subtype = "reportdesign") + public ModelAndView columndel(ModelMap map, HttpServletRequest request, @Valid String id) { + String modelId = ""; + if (!StringUtils.isBlank(id)) { + ColumnProperties col = columnPropertiesRepository.findByIdAndOrgi(id, super.getOrgi(request)); + if (col != null) { + modelId = col.getModelid(); + columnPropertiesRepository.delete(col); + } + } + return request(super.createRequestPageTempletResponse( + "redirect:/apps/report/design/modeldesign.html?id=" + modelId + "&tabid=data")); + } + + /** + * 修改指标 + * + * @param map + * @param request + * @return + */ + @RequestMapping("/columnedit") + @Menu(type = "report", subtype = "reportdesign") + public ModelAndView columnedit(ModelMap map, HttpServletRequest request, @Valid String id) { + if (!StringUtils.isBlank(id)) { + ColumnProperties col = columnPropertiesRepository.findByIdAndOrgi(id, super.getOrgi(request)); + if (col != null) { + map.put("col", col); + } + } + return request(super.createRequestPageTempletResponse("/apps/business/report/design/modeldesign/measureedit")); + } + + /** + * 保存指标 + * + * @param map + * @param request + * @return + */ + @RequestMapping("/columnupdate") + @Menu(type = "report", subtype = "reportdesign") + public ModelAndView columnupdte(ModelMap map, HttpServletRequest request, @Valid String id, @Valid String title, @Valid String mid) { + if (!StringUtils.isBlank(id) && !StringUtils.isBlank(title)) { + ColumnProperties col = columnPropertiesRepository.findByIdAndOrgi(id, super.getOrgi(request)); + if (col != null) { + col.setTitle(title); + columnPropertiesRepository.save(col); + } + } + return request(super.createRequestPageTempletResponse( + "redirect:/apps/report/design/modeldesign.html?id=" + mid + "&tabid=data")); + } + + @RequestMapping("/changetpl") + @Menu(type = "report", subtype = "reportdesign") + public ModelAndView changetpl(ModelMap map, HttpServletRequest request, @Valid String mid, @Valid String tplid) throws Exception { + ReportModel model = this.getModel(mid, super.getOrgi(request)); + if (!StringUtils.isBlank(tplid)) { + model.setTempletid(tplid); + Template tp = templateRes.findByIdAndOrgi(tplid, super.getOrgi(request)); + ChartProperties oldChartppy = model.getChartProperties(); + oldChartppy.setChartype(tp.getCharttype()); + Base64 base64 = new Base64(); + model.setChartcontent(base64.encodeToString(MainUtils.toBytes(oldChartppy))); + reportModelRes.save(model); + } + return request(super.createRequestPageTempletResponse( + "redirect:/apps/report/design/modeldesign.html?id=" + model.getId() + "&tabid=data")); + } + + @RequestMapping("/changechartppy") + @Menu(type = "report", subtype = "reportdesign") + public ModelAndView changechartppy(ModelMap map, HttpServletRequest request, @Valid ReportModel reportModel, @Valid ChartProperties chartProperties, HashMap semap) throws Exception { + ReportModel model = this.getModel(reportModel.getId(), super.getOrgi(request)); + if (null != model) { + model.setExchangerw(reportModel.isExchangerw()); + model.setIsloadfulldata("true".equals(reportModel.getIsloadfulldata()) ? "true" : "false"); + model.setPagesize(reportModel.getPagesize()); + ChartProperties oldChartppy = model.getChartProperties(); + oldChartppy = oldChartppy == null ? new ChartProperties() : oldChartppy; + oldChartppy.setLegen(chartProperties.isLegen()); + oldChartppy.setLegenalign(chartProperties.getLegenalign()); + oldChartppy.setDataview(chartProperties.isDataview()); + oldChartppy.setFormat(StringUtils.isBlank(chartProperties.getFormat()) ? "val" : chartProperties.getFormat()); + Base64 base64 = new Base64(); + model.setChartcontent(base64.encodeToString(MainUtils.toBytes(oldChartppy))); + reportModelRes.save(model); + } + map.addAttribute("eltemplet", templateRes.findByIdAndOrgi(model.getTempletid(), super.getOrgi(request))); + map.addAttribute("element", model); + map.addAttribute("reportModel", model); + if (!StringUtils.isBlank(model.getPublishedcubeid())) { + PublishedCube cube = publishedCubeRepository.findOne(model.getPublishedcubeid()); + map.addAttribute("cube", cube); + if (!model.getMeasures().isEmpty()) { + map.addAttribute("reportData", reportCubeService.getReportData(model, cube.getCube(), request, true, semap)); + } + } + return request(super.createRequestPageTempletResponse("/apps/business/report/design/elementajax")); + } + + /** + * 组件设计 + * + * @param map + * @param request + * @param id + * @return + * @throws Exception + */ + @RequestMapping("/filtervalchange") + @Menu(type = "report", subtype = "reportdesign") + public ModelAndView filtervalchange(ModelMap map, HttpServletRequest request, @Valid String id, @Valid String fid, @Valid String publishedid) + throws Exception { + if (StringUtils.isBlank(publishedid)) { + ReportFilter filter = reportFilterRepository.findByIdAndOrgi(fid, super.getOrgi(request)); + if (filter != null) { + if ("report".equals(filter.getFiltertype())) { + ReportModel model = new ReportModel(); + List reportFilterList = reportFilterRepository.findByReportidAndFiltertypeAndOrgi(filter.getReportid(), "report", super.getOrgi(request)); + model.setFilters(reportFilterList); + map.addAttribute("filter", reportCubeService.processFilter(model, filter, null, request)); + } else { + ReportModel model = this.getModel(id, super.getOrgi(request)); + if (model != null && !StringUtils.isBlank(fid) && !StringUtils.isBlank(model.getPublishedcubeid())) { + PublishedCube cube = publishedCubeRepository.findOne(model.getPublishedcubeid()); + map.addAttribute("filter", reportCubeService.processFilter(model, filter, cube.getCube(), request)); + } + } + } + } else { + PublishedReport publishedReport = publishedReportRes.findById(publishedid); + if (publishedReport != null) { + map.addAttribute("publishedReport", publishedReport); + ReportFilter filter = null; + for (ReportFilter f : publishedReport.getReport().getReportFilters()) { + if (!StringUtils.isBlank(fid) && f.getId().equals(fid)) { + filter = f; + break; + } + } + ReportModel model = null; + for (ReportModel rm : publishedReport.getReport().getReportModels()) { + if (id.equals(rm.getId())) { + model = rm; + } + for (ReportFilter f : rm.getFilters()) { + if (!StringUtils.isBlank(fid) && f.getId().equals(fid)) { + filter = f; + break; + } + } + } + if (filter != null) { + if ("report".equals(filter.getFiltertype())) { + ReportModel modelr = new ReportModel(); + List reportFilterList = publishedReport.getReport().getReportFilters(); + modelr.setFilters(reportFilterList); + map.addAttribute("filter", reportCubeService.processFilter(modelr, filter, null, request)); + } else { + if (model != null && !StringUtils.isBlank(fid) && !StringUtils.isBlank(model.getPublishedcubeid())) { + PublishedCube cube = publishedCubeRepository.findOne(model.getPublishedcubeid()); + map.addAttribute("filter", reportCubeService.processFilter(model, filter, cube.getCube(), request)); + } + } + } + } + } + + return request(super.createRequestPageTempletResponse("/apps/business/report/design/modeldesign/filter")); + } + + @RequestMapping("/editmodelname") + @Menu(type = "report", subtype = "reportdesign") + public ModelAndView editmodelname(ModelMap map, HttpServletRequest request, @Valid String id, @Valid String name) { + map.addAttribute("id", id); + map.addAttribute("name", name); + return request(super.createRequestPageTempletResponse( + "/apps/business/report/design/modeldesign/editmodelname")); + } + + @RequestMapping("/updatemodelname") + @Menu(type = "report", subtype = "reportdesign") + public ModelAndView updatemodelname(ModelMap map, HttpServletRequest request, @Valid String name, @Valid String id) { + ReportModel model = this.getModel(id, super.getOrgi(request)); + if (!StringUtils.isBlank(name)) { + model.setName(name); + reportModelRes.save(model); + } + return request(super.createRequestPageTempletResponse( + "redirect:/apps/report/design/modeldesign.html?id=" + model.getId() + "&tabid=data")); + } + + /** + * 报表发布页面加载 + * + * @param request + * @return + * @throws Exception + */ + @RequestMapping("/reportpublish") + @Menu(type = "report", subtype = "reportdesign") + public ModelAndView reportpublish(ModelMap map, HttpServletRequest request, @Valid String reportid) throws Exception { + map.put("reportid", reportid); + return request(super.createRequestPageTempletResponse("/apps/business/report/reportpublish")); + } + + /** + * 报表发布 + * + * @param request + * @param reportid + * @return + * @throws Exception + */ + @RequestMapping("/reportpublished") + @Menu(type = "report", subtype = "reportdesign") + public ModelAndView reportpublished(ModelMap map, HttpServletRequest request, @Valid String reportid, @Valid String isRecover) throws Exception { + User user = super.getUser(request); + if (!StringUtils.isBlank(reportid)) { + Report report = reportRes.findByIdAndOrgi(reportid, super.getOrgi(request)); + List reportModels = reportModelRes.findByOrgiAndReportid(super.getOrgi(request), reportid); + + for (ReportModel r : reportModels) { + getModel(r.getId(), super.getOrgi(request)); + } + report.setReportModels(reportModels); + List reportFilters = reportCubeService.fillReportFilterData(reportFilterRepository.findByReportidAndFiltertypeAndOrgi(reportid, "report", super.getOrgi(request)), request); + report.setReportFilters(reportFilters); + PublishedReport publishedReport = new PublishedReport(); + MainUtils.copyProperties(report, publishedReport, ""); + publishedReport.setId(null); + Base64 base64 = new Base64(); + publishedReport.setReportcontent(base64.encodeToString(MainUtils.toBytes(report))); + publishedReport.setDataid(reportid); + publishedReport.setCreatetime(new Date()); + publishedReport.setCreater(user.getId()); + List pbReportList = publishedReportRes.findByOrgiAndDataidOrderByDataversionDesc(super.getOrgi(request), reportid); + if (!pbReportList.isEmpty()) { + int maxVersion = pbReportList.get(0).getDataversion(); + if ("yes".equals(isRecover)) { + publishedReport.setId(pbReportList.get(0).getId()); + publishedReport.setDataversion(pbReportList.get(0).getDataversion()); + publishedReportRes.save(publishedReport); + } else if ("no".equals(isRecover)) { + publishedReport.setDataversion(maxVersion + 1); + publishedReportRes.save(publishedReport); + } else { + publishedReportRes.deleteAll(pbReportList); + publishedReport.setDataversion(1); + publishedReportRes.save(publishedReport); + } + } else { + publishedReport.setDataversion(1); + publishedReportRes.save(publishedReport); + } + return request(super.createRequestPageTempletResponse("redirect:/apps/report/index.html?dicid=" + publishedReport.getDicid())); + } + return request(super.createRequestPageTempletResponse("redirect:/apps/report/index.html")); + } +} diff --git a/contact-center/app/src/main/java/com/chatopera/cc/persistence/repository/TablePropertiesRepository.java b/contact-center/app/src/main/java/com/chatopera/cc/persistence/repository/TablePropertiesRepository.java index d185835c..418b5ac9 100644 --- a/contact-center/app/src/main/java/com/chatopera/cc/persistence/repository/TablePropertiesRepository.java +++ b/contact-center/app/src/main/java/com/chatopera/cc/persistence/repository/TablePropertiesRepository.java @@ -1,35 +1,35 @@ -/* - * Copyright (C) 2017 优客服-多渠道客服系统 - * Modifications copyright (C) 2018-2019 Chatopera Inc, - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.chatopera.cc.persistence.repository; - -import com.chatopera.cc.model.TableProperties; -import org.springframework.data.jpa.repository.JpaRepository; - -import java.util.List; - -public interface TablePropertiesRepository extends JpaRepository{ - - TableProperties findById(String id); - - List findByDbtableid(String dbtableid) ; - - List findByTablename(String tablename) ; - - List findBySecfield(boolean secfield) ; - - TableProperties findByTablenameAndFieldname(String tablename, String fieldname) ; -} +/* + * Copyright (C) 2017 优客服-多渠道客服系统 + * Modifications copyright (C) 2018-2019 Chatopera Inc, + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.chatopera.cc.persistence.repository; + +import com.chatopera.cc.model.TableProperties; +import org.springframework.data.jpa.repository.JpaRepository; + +import java.util.List; + +public interface TablePropertiesRepository extends JpaRepository { + + // TableProperties findById(String id); + + List findByDbtableid(String dbtableid); + + List findByTablename(String tablename); + + List findBySecfield(boolean secfield); + + // TableProperties findByTablenameAndFieldname(String tablename, String fieldname) ; +}