1
0
mirror of https://github.com/chatopera/cosin.git synced 2025-08-01 16:38:02 +08:00

Fix TablePropertiesRepository related class

This commit is contained in:
dengchao@xgtl 2020-04-16 15:23:11 +08:00
parent f6a09e8c48
commit 192c664db0
7 changed files with 1923 additions and 1920 deletions

View File

@ -1,136 +1,136 @@
/* /*
* Copyright (C) 2017 优客服-多渠道客服系统 * Copyright (C) 2017 优客服-多渠道客服系统
* Modifications copyright (C) 2018-2019 Chatopera Inc, <https://www.chatopera.com> * Modifications copyright (C) 2018-2019 Chatopera Inc, <https://www.chatopera.com>
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
* You may obtain a copy of the License at * You may obtain a copy of the License at
* *
* http://www.apache.org/licenses/LICENSE-2.0 * http://www.apache.org/licenses/LICENSE-2.0
* *
* Unless required by applicable law or agreed to in writing, software * Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, * distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*/ */
package com.chatopera.cc.config; package com.chatopera.cc.config;
import com.chatopera.cc.basic.Constants; import com.chatopera.cc.basic.Constants;
import com.chatopera.cc.basic.MainContext; import com.chatopera.cc.basic.MainContext;
import com.chatopera.cc.basic.MainUtils; import com.chatopera.cc.basic.MainUtils;
import com.chatopera.cc.cache.Cache; import com.chatopera.cc.cache.Cache;
import com.chatopera.cc.model.BlackEntity; import com.chatopera.cc.model.BlackEntity;
import com.chatopera.cc.model.SysDic; import com.chatopera.cc.model.SysDic;
import com.chatopera.cc.model.SystemConfig; import com.chatopera.cc.model.SystemConfig;
import com.chatopera.cc.persistence.repository.BlackListRepository; import com.chatopera.cc.persistence.repository.BlackListRepository;
import com.chatopera.cc.persistence.repository.SysDicRepository; import com.chatopera.cc.persistence.repository.SysDicRepository;
import com.chatopera.cc.persistence.repository.SystemConfigRepository; import com.chatopera.cc.persistence.repository.SystemConfigRepository;
import com.chatopera.cc.persistence.repository.TablePropertiesRepository; import com.chatopera.cc.persistence.repository.TablePropertiesRepository;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import org.springframework.context.ApplicationListener; import org.springframework.context.ApplicationListener;
import org.springframework.context.event.ContextRefreshedEvent; import org.springframework.context.event.ContextRefreshedEvent;
import java.util.*; import java.util.*;
public class AppCtxRefreshEventListener implements ApplicationListener<ContextRefreshedEvent> { public class AppCtxRefreshEventListener implements ApplicationListener<ContextRefreshedEvent> {
private static final Logger logger = LoggerFactory.getLogger(AppCtxRefreshEventListener.class); private static final Logger logger = LoggerFactory.getLogger(AppCtxRefreshEventListener.class);
@Override @Override
public void onApplicationEvent(ContextRefreshedEvent event) { public void onApplicationEvent(ContextRefreshedEvent event) {
if (MainContext.getContext() == null) { if (MainContext.getContext() == null) {
logger.info("[onApplicationEvent] set main context and initialize the Cache System."); logger.info("[onApplicationEvent] set main context and initialize the Cache System.");
MainContext.setApplicationContext(event.getApplicationContext()); MainContext.setApplicationContext(event.getApplicationContext());
SysDicRepository sysDicRes = event.getApplicationContext().getBean(SysDicRepository.class); SysDicRepository sysDicRes = event.getApplicationContext().getBean(SysDicRepository.class);
BlackListRepository blackListRes = event.getApplicationContext().getBean(BlackListRepository.class); BlackListRepository blackListRes = event.getApplicationContext().getBean(BlackListRepository.class);
Cache cache = event.getApplicationContext().getBean(Cache.class); Cache cache = event.getApplicationContext().getBean(Cache.class);
String cacheSetupStrategy = event.getApplicationContext().getEnvironment().getProperty("cache.setup.strategy"); String cacheSetupStrategy = event.getApplicationContext().getEnvironment().getProperty("cache.setup.strategy");
if (!StringUtils.equalsIgnoreCase(cacheSetupStrategy, Constants.cache_setup_strategy_skip)) { if (!StringUtils.equalsIgnoreCase(cacheSetupStrategy, Constants.cache_setup_strategy_skip)) {
/************************** /**************************
* 加载系统到缓存 * 加载系统到缓存
* 加载系统词典大约只需要5s左右 * 加载系统词典大约只需要5s左右
**************************/ **************************/
// 首先将之前缓存清空此处使用系统的默认租户信息 // 首先将之前缓存清空此处使用系统的默认租户信息
cache.eraseSysDicByOrgi(MainContext.SYSTEM_ORGI); cache.eraseSysDicByOrgi(MainContext.SYSTEM_ORGI);
List<SysDic> sysDicList = sysDicRes.findAll(); List<SysDic> sysDicList = sysDicRes.findAll();
Map<String, List<SysDic>> rootDictItems = new HashMap<>(); // 关联根词典及其子项 Map<String, List<SysDic>> rootDictItems = new HashMap<>(); // 关联根词典及其子项
Map<String, SysDic> rootDics = new HashMap<>(); Map<String, SysDic> rootDics = new HashMap<>();
Set<String> parents = new HashSet<>(); Set<String> parents = new HashSet<>();
// 获得所有根词典 // 获得所有根词典
for (final SysDic dic : sysDicList) { for (final SysDic dic : sysDicList) {
if (StringUtils.equals(dic.getParentid(), "0")) { if (StringUtils.equals(dic.getParentid(), "0")) {
parents.add(dic.getId()); parents.add(dic.getId());
rootDics.put(dic.getId(), dic); rootDics.put(dic.getId(), dic);
} }
} }
// 向根词典中添加子项 // 向根词典中添加子项
for (final SysDic dic : sysDicList) { for (final SysDic dic : sysDicList) {
if ((!StringUtils.equals(dic.getParentid(), "0")) && if ((!StringUtils.equals(dic.getParentid(), "0")) &&
parents.contains(dic.getDicid())) { parents.contains(dic.getDicid())) {
// 不是根词典并且包含在一个根词典内 // 不是根词典并且包含在一个根词典内
if (!rootDictItems.containsKey(dic.getDicid())) { if (!rootDictItems.containsKey(dic.getDicid())) {
rootDictItems.put(dic.getDicid(), new ArrayList<SysDic>()); rootDictItems.put(dic.getDicid(), new ArrayList<SysDic>());
} }
rootDictItems.get(dic.getDicid()).add(dic); rootDictItems.get(dic.getDicid()).add(dic);
} }
} }
// 更新缓存 // 更新缓存
// TODO 集群时注意!!! // TODO 集群时注意!!!
// 此处为长时间的操作如果在一个集群中会操作共享内容非常不可靠 // 此处为长时间的操作如果在一个集群中会操作共享内容非常不可靠
// 所以当前代码不支持集群需要解决启动上的这个问题 // 所以当前代码不支持集群需要解决启动上的这个问题
// 存储根词典 TODO 此处只考虑了系统默认租户 // 存储根词典 TODO 此处只考虑了系统默认租户
cache.putSysDicByOrgi(new ArrayList<>(rootDics.values()), MainContext.SYSTEM_ORGI); cache.putSysDicByOrgi(new ArrayList<>(rootDics.values()), MainContext.SYSTEM_ORGI);
for (final Map.Entry<String, List<SysDic>> entry : rootDictItems.entrySet()) { for (final Map.Entry<String, List<SysDic>> entry : rootDictItems.entrySet()) {
SysDic rootDic = rootDics.get(entry.getKey()); 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()); 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(rootDic.getCode(), MainContext.SYSTEM_ORGI, entry.getValue());
// 存储子项成员 // 存储子项成员
cache.putSysDicByOrgi(entry.getValue(), MainContext.SYSTEM_ORGI); cache.putSysDicByOrgi(entry.getValue(), MainContext.SYSTEM_ORGI);
} }
List<BlackEntity> blackList = blackListRes.findByOrgi(MainContext.SYSTEM_ORGI); List<BlackEntity> blackList = blackListRes.findByOrgi(MainContext.SYSTEM_ORGI);
for (final BlackEntity black : blackList) { for (final BlackEntity black : blackList) {
if (StringUtils.isNotBlank(black.getUserid())) { if (StringUtils.isNotBlank(black.getUserid())) {
if (black.getEndtime() == null || black.getEndtime().after(new Date())) { if (black.getEndtime() == null || black.getEndtime().after(new Date())) {
cache.putSystemByIdAndOrgi(black.getUserid(), black.getOrgi(), black); cache.putSystemByIdAndOrgi(black.getUserid(), black.getOrgi(), black);
} }
} }
} }
/** /*
* 加载系统全局配置 * 加载系统全局配置
*/ */
SystemConfigRepository systemConfigRes = event.getApplicationContext().getBean(SystemConfigRepository.class); SystemConfigRepository systemConfigRes = event.getApplicationContext().getBean(SystemConfigRepository.class);
SystemConfig config = systemConfigRes.findByOrgi(MainContext.SYSTEM_ORGI); SystemConfig config = systemConfigRes.findByOrgi(MainContext.SYSTEM_ORGI);
if (config != null) { if (config != null) {
cache.putSystemByIdAndOrgi("systemConfig", MainContext.SYSTEM_ORGI, config); cache.putSystemByIdAndOrgi("systemConfig", MainContext.SYSTEM_ORGI, config);
} }
logger.info("[StartedEventListener] setup Sysdicts in Redis done, strategy {}", cacheSetupStrategy); logger.info("[StartedEventListener] setup Sysdicts in Redis done, strategy {}", cacheSetupStrategy);
} else { } else {
logger.info("[onApplicationEvent] skip initialize sysdicts."); logger.info("[onApplicationEvent] skip initialize sysdicts.");
} }
MainUtils.initSystemArea(); MainUtils.initSystemArea();
MainUtils.initSystemSecField(event.getApplicationContext().getBean(TablePropertiesRepository.class)); MainUtils.initSystemSecField(event.getApplicationContext().getBean(TablePropertiesRepository.class));
// MainUtils.initAdv();//初始化广告位 // MainUtils.initAdv();//初始化广告位
} else { } else {
logger.info("[onApplicationEvent] bypass, initialization has been done already."); logger.info("[onApplicationEvent] bypass, initialization has been done already.");
} }
} }
} }

View File

@ -29,26 +29,26 @@ import com.chatopera.cc.util.Menu;
import com.chatopera.cc.util.metadata.DatabaseMetaDataHandler; import com.chatopera.cc.util.metadata.DatabaseMetaDataHandler;
import com.chatopera.cc.util.metadata.UKColumnMetadata; import com.chatopera.cc.util.metadata.UKColumnMetadata;
import com.chatopera.cc.util.metadata.UKTableMetaData; import com.chatopera.cc.util.metadata.UKTableMetaData;
import lombok.RequiredArgsConstructor;
import org.apache.commons.lang.StringUtils; import org.apache.commons.lang.StringUtils;
import org.hibernate.Session; import org.hibernate.Session;
import org.hibernate.jdbc.Work;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import org.springframework.beans.BeansException; import org.springframework.beans.BeansException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.PageRequest; import org.springframework.data.domain.PageRequest;
import org.springframework.data.elasticsearch.repository.ElasticsearchRepository; 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.stereotype.Controller;
import org.springframework.ui.ModelMap; import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.server.ResponseStatusException;
import org.springframework.web.servlet.ModelAndView; import org.springframework.web.servlet.ModelAndView;
import javax.persistence.EntityManager; import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext; import javax.persistence.PersistenceContext;
import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletRequest;
import javax.validation.Valid; import javax.validation.Valid;
import java.sql.Connection;
import java.sql.SQLException;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
import java.util.Date; import java.util.Date;
@ -56,43 +56,39 @@ import java.util.List;
@Controller @Controller
@RequestMapping("/admin/metadata") @RequestMapping("/admin/metadata")
@RequiredArgsConstructor
public class MetadataController extends Handler { 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); private static final Logger logger = LoggerFactory.getLogger(MetadataController.class);
@NonNull
@Autowired private final MetadataRepository metadataRes;
@NonNull
private final BaseService<?> service;
@NonNull
private final SysDicRepository sysDicRes;
@NonNull
private final TablePropertiesRepository tablePropertiesRes;
@NonNull
@PersistenceContext @PersistenceContext
private EntityManager em; private final EntityManager em;
@RequestMapping("/index") @RequestMapping("/index")
@Menu(type = "admin", subtype = "metadata", admin = true) @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)))); map.addAttribute("metadataList", metadataRes.findAll(PageRequest.of(super.getP(request), super.getPs(request))));
return request(super.createAdminTempletResponse("/admin/system/metadata/index")); return request(super.createAdminTempletResponse("/admin/system/metadata/index"));
} }
@RequestMapping("/edit") @RequestMapping("/edit")
@Menu(type = "admin", subtype = "metadata", admin = true) @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)); map.addAttribute("metadata", metadataRes.findById(id));
return request(super.createRequestPageTempletResponse("/admin/system/metadata/edit")); return request(super.createRequestPageTempletResponse("/admin/system/metadata/edit"));
} }
@RequestMapping("/update") @RequestMapping("/update")
@Menu(type = "admin", subtype = "metadata", admin = true) @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()); MetadataTable table = metadataRes.findById(metadata.getId());
table.setName(metadata.getName()); table.setName(metadata.getName());
table.setFromdb(metadata.isFromdb()); table.setFromdb(metadata.isFromdb());
@ -104,7 +100,7 @@ public class MetadataController extends Handler {
@RequestMapping("/properties/edit") @RequestMapping("/properties/edit")
@Menu(type = "admin", subtype = "metadata", admin = true) @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("tp", tablePropertiesRes.findById(id));
map.addAttribute("sysdicList", sysDicRes.findByParentid("0")); map.addAttribute("sysdicList", sysDicRes.findByParentid("0"));
map.addAttribute("dataImplList", Dict.getInstance().getDic("com.dic.data.impl")); map.addAttribute("dataImplList", Dict.getInstance().getDic("com.dic.data.impl"));
@ -114,8 +110,9 @@ public class MetadataController extends Handler {
@RequestMapping("/properties/update") @RequestMapping("/properties/update")
@Menu(type = "admin", subtype = "metadata", admin = true) @Menu(type = "admin", subtype = "metadata", admin = true)
public ModelAndView propertiesupdate(ModelMap map, HttpServletRequest request, @Valid TableProperties tp) throws SQLException { public ModelAndView propertiesupdate(@Valid TableProperties tp) {
TableProperties tableProperties = tablePropertiesRes.findById(tp.getId()); 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.setName(tp.getName());
tableProperties.setSeldata(tp.isSeldata()); tableProperties.setSeldata(tp.isSeldata());
tableProperties.setSeldatacode(tp.getSeldatacode()); tableProperties.setSeldatacode(tp.getSeldatacode());
@ -139,7 +136,7 @@ public class MetadataController extends Handler {
@RequestMapping("/delete") @RequestMapping("/delete")
@Menu(type = "admin", subtype = "metadata", admin = true) @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); MetadataTable table = metadataRes.findById(id);
metadataRes.delete(table); metadataRes.delete(table);
return request(super.createRequestPageTempletResponse("redirect:/admin/metadata/index.html")); return request(super.createRequestPageTempletResponse("redirect:/admin/metadata/index.html"));
@ -147,33 +144,34 @@ public class MetadataController extends Handler {
@RequestMapping("/batdelete") @RequestMapping("/batdelete")
@Menu(type = "admin", subtype = "metadata", admin = true) @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) { 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")); return request(super.createRequestPageTempletResponse("redirect:/admin/metadata/index.html"));
} }
@RequestMapping("/properties/delete") @RequestMapping("/properties/delete")
@Menu(type = "admin", subtype = "metadata", admin = true) @Menu(type = "admin", subtype = "metadata", admin = true)
public ModelAndView propertiesdelete(ModelMap map, HttpServletRequest request, @Valid String id, @Valid String tbid) throws SQLException { public ModelAndView propertiesdelete(@Valid String id, @Valid String tbid) {
TableProperties prop = tablePropertiesRes.findById(id); TableProperties prop = tablePropertiesRes.findById(id)
.orElseThrow(() -> new ResponseStatusException(HttpStatus.NOT_FOUND, String.format("Table properties %s not found", id)));
tablePropertiesRes.delete(prop); tablePropertiesRes.delete(prop);
return request(super.createRequestPageTempletResponse("redirect:/admin/metadata/table.html?id=" + (!StringUtils.isBlank(tbid) ? tbid : prop.getDbtableid()))); return request(super.createRequestPageTempletResponse("redirect:/admin/metadata/table.html?id=" + (!StringUtils.isBlank(tbid) ? tbid : prop.getDbtableid())));
} }
@RequestMapping("/properties/batdelete") @RequestMapping("/properties/batdelete")
@Menu(type = "admin", subtype = "metadata", admin = true) @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) { 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)); return request(super.createRequestPageTempletResponse("redirect:/admin/metadata/table.html?id=" + tbid));
} }
@RequestMapping("/table") @RequestMapping("/table")
@Menu(type = "admin", subtype = "metadata", admin = true) @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("propertiesList", tablePropertiesRes.findByDbtableid(id));
map.addAttribute("tbid", id); map.addAttribute("tbid", id);
map.addAttribute("table", metadataRes.findById(id)); map.addAttribute("table", metadataRes.findById(id));
@ -182,17 +180,15 @@ public class MetadataController extends Handler {
@RequestMapping("/imptb") @RequestMapping("/imptb")
@Menu(type = "admin", subtype = "metadata", admin = true) @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 session = (Session) em.getDelegate();
session.doWork(new Work() { session.doWork(connection -> {
public void execute(Connection connection) throws SQLException { try {
try { map.addAttribute("tablesList",
map.addAttribute("tablesList", DatabaseMetaDataHandler.getTables(connection));
DatabaseMetaDataHandler.getTables(connection)); } catch (Exception e) {
} catch (Exception e) { logger.error("When import metadata", e);
logger.error("When import metadata", e);
}
} }
}); });
@ -202,34 +198,32 @@ public class MetadataController extends Handler {
@RequestMapping("/imptbsave") @RequestMapping("/imptbsave")
@Menu(type = "admin", subtype = "metadata", admin = true) @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); final User user = super.getUser(request);
if (tables != null && tables.length > 0) { if (tables != null && tables.length > 0) {
Session session = (Session) em.getDelegate(); Session session = (Session) em.getDelegate();
session.doWork( session.doWork(
new Work() { connection -> {
public void execute(Connection connection) throws SQLException { try {
try { for (String table : tables) {
for (String table : tables) { int count = metadataRes.countByTablename(table);
int count = metadataRes.countByTablename(table); if (count == 0) {
if (count == 0) { MetadataTable metaDataTable = new MetadataTable();
MetadataTable metaDataTable = new MetadataTable(); //当前记录没有被添加过进行正常添加
//当前记录没有被添加过进行正常添加 metaDataTable.setTablename(table);
metaDataTable.setTablename(table); metaDataTable.setOrgi(user.getOrgi());
metaDataTable.setOrgi(user.getOrgi()); metaDataTable.setId(MainUtils.md5(metaDataTable.getTablename()));
metaDataTable.setId(MainUtils.md5(metaDataTable.getTablename())); metaDataTable.setTabledirid("0");
metaDataTable.setTabledirid("0"); metaDataTable.setCreater(user.getId());
metaDataTable.setCreater(user.getId()); metaDataTable.setCreatername(user.getUsername());
metaDataTable.setCreatername(user.getUsername()); metaDataTable.setName(table);
metaDataTable.setName(table); metaDataTable.setUpdatetime(new Date());
metaDataTable.setUpdatetime(new Date()); metaDataTable.setCreatetime(new Date());
metaDataTable.setCreatetime(new Date()); metadataRes.save(processMetadataTable(DatabaseMetaDataHandler.getTable(connection, metaDataTable.getTablename()), metaDataTable));
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) { private MetadataTable processMetadataTable(UKTableMetaData metaData, MetadataTable table) {
table.setTableproperty(new ArrayList<TableProperties>()); table.setTableproperty(new ArrayList<>());
if (metaData != null) { if (metaData != null) {
for (UKColumnMetadata colum : metaData.getColumnMetadatas()) { for (UKColumnMetadata colum : metaData.getColumnMetadatas()) {
TableProperties tablePorperties = new TableProperties(colum.getName().toLowerCase(), colum.getTypeName(), colum.getColumnSize(), metaData.getName().toLowerCase()); 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) { public String getDataTypeName(String type) {
String typeName = "text"; String typeName = "text";
if (type.indexOf("varchar") >= 0) { if (type.contains("varchar")) {
typeName = "text"; typeName = "text";
} else if (type.equalsIgnoreCase("date") || type.equalsIgnoreCase("datetime")) { } else if (type.equalsIgnoreCase("date") || type.equalsIgnoreCase("datetime")) {
typeName = type.toLowerCase(); typeName = type.toLowerCase();
@ -275,7 +269,7 @@ public class MetadataController extends Handler {
@RequestMapping("/clean") @RequestMapping("/clean")
@Menu(type = "admin", subtype = "metadata", admin = true) @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)) { if (!StringUtils.isBlank(id)) {
MetadataTable table = metadataRes.findById(id); MetadataTable table = metadataRes.findById(id);
if (table.isFromdb() && !StringUtils.isBlank(table.getListblocktemplet())) { if (table.isFromdb() && !StringUtils.isBlank(table.getListblocktemplet())) {
@ -295,7 +289,7 @@ public class MetadataController extends Handler {
@SuppressWarnings({"rawtypes", "unchecked"}) @SuppressWarnings({"rawtypes", "unchecked"})
@RequestMapping("/synctoes") @RequestMapping("/synctoes")
@Menu(type = "admin", subtype = "metadata", admin = true) @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)) { if (!StringUtils.isBlank(id)) {
MetadataTable table = metadataRes.findById(id); MetadataTable table = metadataRes.findById(id);
if (table.isFromdb() && !StringUtils.isBlank(table.getListblocktemplet())) { if (table.isFromdb() && !StringUtils.isBlank(table.getListblocktemplet())) {
@ -309,9 +303,7 @@ public class MetadataController extends Handler {
SysDic jpaDic = Dict.getInstance().getDicItem(table.getPreviewtemplet()); SysDic jpaDic = Dict.getInstance().getDicItem(table.getPreviewtemplet());
List dataList = service.list(jpaDic.getCode()); List dataList = service.list(jpaDic.getCode());
List values = new CskefuList(); List values = new CskefuList();
for (Object object : dataList) { values.addAll(dataList);
values.add(object);
}
if (dataList.size() > 0) { if (dataList.size() > 0) {
jpa.save(values); jpa.save(values);
} }
@ -326,7 +318,7 @@ public class MetadataController extends Handler {
@SuppressWarnings({"rawtypes"}) @SuppressWarnings({"rawtypes"})
@RequestMapping("/synctodb") @RequestMapping("/synctodb")
@Menu(type = "admin", subtype = "metadata", admin = true) @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)) { if (!StringUtils.isBlank(id)) {
MetadataTable table = metadataRes.findById(id); MetadataTable table = metadataRes.findById(id);
if (table.isFromdb() && !StringUtils.isBlank(table.getListblocktemplet())) { if (table.isFromdb() && !StringUtils.isBlank(table.getListblocktemplet())) {

View File

@ -1,161 +1,167 @@
/* /*
* Copyright (C) 2017 优客服-多渠道客服系统 * Copyright (C) 2017 优客服-多渠道客服系统
* Modifications copyright (C) 2018-2019 Chatopera Inc, <https://www.chatopera.com> * Modifications copyright (C) 2018-2019 Chatopera Inc, <https://www.chatopera.com>
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
* You may obtain a copy of the License at * You may obtain a copy of the License at
* *
* http://www.apache.org/licenses/LICENSE-2.0 * http://www.apache.org/licenses/LICENSE-2.0
* *
* Unless required by applicable law or agreed to in writing, software * Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, * distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*/ */
package com.chatopera.cc.controller.apps.report; package com.chatopera.cc.controller.apps.report;
import com.chatopera.cc.controller.Handler; import com.chatopera.cc.controller.Handler;
import com.chatopera.cc.model.CubeLevel; import com.chatopera.cc.model.CubeLevel;
import com.chatopera.cc.model.CubeMetadata; import com.chatopera.cc.model.CubeMetadata;
import com.chatopera.cc.model.Dimension; import com.chatopera.cc.model.Dimension;
import com.chatopera.cc.model.TableProperties; import com.chatopera.cc.model.TableProperties;
import com.chatopera.cc.persistence.repository.CubeLevelRepository; import com.chatopera.cc.persistence.repository.CubeLevelRepository;
import com.chatopera.cc.persistence.repository.CubeMetadataRepository; import com.chatopera.cc.persistence.repository.CubeMetadataRepository;
import com.chatopera.cc.persistence.repository.DimensionRepository; import com.chatopera.cc.persistence.repository.DimensionRepository;
import com.chatopera.cc.persistence.repository.TablePropertiesRepository; import com.chatopera.cc.persistence.repository.TablePropertiesRepository;
import com.chatopera.cc.util.Menu; import com.chatopera.cc.util.Menu;
import org.apache.commons.lang.StringUtils; import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired; import org.apache.commons.lang.StringUtils;
import org.springframework.stereotype.Controller; import org.springframework.http.HttpStatus;
import org.springframework.ui.ModelMap; import org.springframework.lang.NonNull;
import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.stereotype.Controller;
import org.springframework.web.servlet.ModelAndView; import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import javax.servlet.http.HttpServletRequest; import org.springframework.web.server.ResponseStatusException;
import javax.validation.Valid; import org.springframework.web.servlet.ModelAndView;
import java.util.List;
import javax.servlet.http.HttpServletRequest;
@Controller import javax.validation.Valid;
@RequestMapping("/apps/report/cubelevel") import java.util.List;
public class CubeLevelController extends Handler{
@Controller
@Autowired @RequestMapping("/apps/report/cubelevel")
private CubeLevelRepository cubeLevelRes; @RequiredArgsConstructor
public class CubeLevelController extends Handler {
@Autowired
private DimensionRepository dimensionRes; @NonNull
private final CubeLevelRepository cubeLevelRes;
@Autowired
private TablePropertiesRepository tablePropertiesRes; @NonNull
private final DimensionRepository dimensionRes;
@Autowired
private CubeMetadataRepository cubeMetadataRes; @NonNull
private final TablePropertiesRepository tablePropertiesRes;
@RequestMapping("/add")
@Menu(type = "report" , subtype = "cubelevel") @NonNull
public ModelAndView cubeLeveladd(ModelMap map , HttpServletRequest request , @Valid String cubeid,@Valid String dimid) { private final CubeMetadataRepository cubeMetadataRes;
map.addAttribute("cubeid", cubeid);
map.addAttribute("dimid", dimid); @RequestMapping("/add")
//map.addAttribute("fktableList",cubeMetadataRes.findByCubeid(cubeid)); @Menu(type = "report", subtype = "cubelevel")
Dimension dim = dimensionRes.findByIdAndOrgi(dimid,super.getOrgi(request)); public ModelAndView cubeLeveladd(ModelMap map, HttpServletRequest request, @Valid String cubeid, @Valid String dimid) {
map.addAttribute("cubeid", cubeid);
if(dim!=null){ map.addAttribute("dimid", dimid);
if(!StringUtils.isBlank(dim.getFktable())) { //map.addAttribute("fktableList",cubeMetadataRes.findByCubeid(cubeid));
map.put("fktableidList", tablePropertiesRes.findByDbtableid(dim.getFktable())); Dimension dim = dimensionRes.findByIdAndOrgi(dimid, super.getOrgi(request));
}else {
List<CubeMetadata> cmList = cubeMetadataRes.findByCubeidAndMtype(cubeid,"0"); if (dim != null) {
if(!cmList.isEmpty() && cmList.get(0)!=null) { if (!StringUtils.isBlank(dim.getFktable())) {
map.put("fktableidList", tablePropertiesRes.findByDbtableid(cmList.get(0).getTb().getId())); map.put("fktableidList", tablePropertiesRes.findByDbtableid(dim.getFktable()));
} } else {
} List<CubeMetadata> 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" ) return request(super.createRequestPageTempletResponse("/apps/business/report/cube/cubelevel/add"));
public ModelAndView cubeLevelsave(ModelMap map , HttpServletRequest request , @Valid CubeLevel cubeLevel,@Valid String tableid) { }
if(!StringUtils.isBlank(cubeLevel.getName())){
cubeLevel.setOrgi(super.getOrgi(request)); @RequestMapping("/save")
cubeLevel.setCreater(super.getUser(request).getId()); @Menu(type = "report", subtype = "cubelevel")
cubeLevel.setCode(cubeLevel.getColumname()); public ModelAndView cubeLevelsave(HttpServletRequest request, @Valid CubeLevel cubeLevel, @Valid String tableid) {
if(!StringUtils.isBlank(tableid)) { if (!StringUtils.isBlank(cubeLevel.getName())) {
TableProperties tb = new TableProperties(); cubeLevel.setOrgi(super.getOrgi(request));
tb.setId(tableid); cubeLevel.setCreater(super.getUser(request).getId());
TableProperties t = tablePropertiesRes.findById(tableid); cubeLevel.setCode(cubeLevel.getColumname());
cubeLevel.setTablename(t.getTablename()); if (!StringUtils.isBlank(tableid)) {
cubeLevel.setCode(t.getFieldname()); TableProperties tb = new TableProperties();
cubeLevel.setColumname(t.getFieldname()); tb.setId(tableid);
cubeLevel.setTableproperty(tb); TableProperties t = tablePropertiesRes.findById(tableid)
} .orElseThrow(() -> new ResponseStatusException(HttpStatus.NOT_FOUND, String.format("Table properties %s not found", tableid)));
cubeLevelRes.save(cubeLevel) ; cubeLevel.setTablename(t.getTablename());
} cubeLevel.setCode(t.getFieldname());
return request(super.createRequestPageTempletResponse("redirect:/apps/report/cube/detail.html?id="+cubeLevel.getCubeid()+"&dimensionId="+cubeLevel.getDimid())); cubeLevel.setColumname(t.getFieldname());
} cubeLevel.setTableproperty(tb);
}
@RequestMapping("/delete") cubeLevelRes.save(cubeLevel);
@Menu(type = "report" , subtype = "cubelevel" ) }
public ModelAndView quickreplydelete(ModelMap map , HttpServletRequest request , @Valid String id) { return request(super.createRequestPageTempletResponse("redirect:/apps/report/cube/detail.html?id=" + cubeLevel.getCubeid() + "&dimensionId=" + cubeLevel.getDimid()));
CubeLevel cubeLevel = cubeLevelRes.findOne(id) ; }
if(cubeLevel!=null){
cubeLevelRes.delete(cubeLevel); @RequestMapping("/delete")
} @Menu(type = "report", subtype = "cubelevel")
return request(super.createRequestPageTempletResponse("redirect:/apps/report/cube/detail.html?id="+cubeLevel.getCubeid()+"&dimensionId="+cubeLevel.getDimid())); public ModelAndView quickreplydelete(@Valid String id) {
} CubeLevel cubeLevel = cubeLevelRes.findById(id)
@RequestMapping("/edit") .orElseThrow(() -> new ResponseStatusException(HttpStatus.NOT_FOUND, String.format("Cube level %s not found", id)));
@Menu(type = "report" , subtype = "cubelevel" , admin= true) cubeLevelRes.delete(cubeLevel);
public ModelAndView quickreplyedit(ModelMap map , HttpServletRequest request , @Valid String id) { return request(super.createRequestPageTempletResponse("redirect:/apps/report/cube/detail.html?id=" + cubeLevel.getCubeid() + "&dimensionId=" + cubeLevel.getDimid()));
CubeLevel cubeLevel = cubeLevelRes.findOne(id) ; }
map.put("cubeLevel", cubeLevel) ;
Dimension dim = dimensionRes.findByIdAndOrgi(cubeLevel.getDimid(),super.getOrgi(request)); @RequestMapping("/edit")
if(dim!=null){ @Menu(type = "report", subtype = "cubelevel", admin = true)
if(!StringUtils.isBlank(dim.getFktable())) { public ModelAndView quickreplyedit(ModelMap map, HttpServletRequest request, @Valid String id) {
map.put("fktableidList", tablePropertiesRes.findByDbtableid(dim.getFktable())); CubeLevel cubeLevel = cubeLevelRes.findById(id)
map.addAttribute("tableid", dim.getFktable()); .orElseThrow(() -> new ResponseStatusException(HttpStatus.NOT_FOUND, String.format("Cube level %s not found", id)));
}else { map.put("cubeLevel", cubeLevel);
List<CubeMetadata> cmList = cubeMetadataRes.findByCubeidAndMtype(cubeLevel.getCubeid(),"0"); Dimension dim = dimensionRes.findByIdAndOrgi(cubeLevel.getDimid(), super.getOrgi(request));
if(!cmList.isEmpty() && cmList.get(0)!=null) { if (dim != null) {
map.put("fktableidList", tablePropertiesRes.findByDbtableid(cmList.get(0).getTb().getId())); if (!StringUtils.isBlank(dim.getFktable())) {
map.addAttribute("tableid", cmList.get(0).getId()); map.put("fktableidList", tablePropertiesRes.findByDbtableid(dim.getFktable()));
} map.addAttribute("tableid", dim.getFktable());
} } else {
List<CubeMetadata> cmList = cubeMetadataRes.findByCubeidAndMtype(cubeLevel.getCubeid(), "0");
} if (!cmList.isEmpty() && cmList.get(0) != null) {
return request(super.createRequestPageTempletResponse("/apps/business/report/cube/cubelevel/edit")); map.put("fktableidList", tablePropertiesRes.findByDbtableid(cmList.get(0).getTb().getId()));
} map.addAttribute("tableid", cmList.get(0).getId());
}
@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())){ return request(super.createRequestPageTempletResponse("/apps/business/report/cube/cubelevel/edit"));
CubeLevel temp = cubeLevelRes.findOne(cubeLevel.getId()) ; }
cubeLevel.setOrgi(super.getOrgi(request));
cubeLevel.setCreater(super.getUser(request).getId()); @RequestMapping("/update")
if(temp!=null){ @Menu(type = "report", subtype = "cubelevel", admin = true)
cubeLevel.setCreatetime(temp.getCreatetime()); public ModelAndView quickreplyupdate(HttpServletRequest request, @Valid CubeLevel cubeLevel, @Valid String tableid) {
} if (!StringUtils.isBlank(cubeLevel.getId())) {
if(!StringUtils.isBlank(tableid)) { cubeLevel.setOrgi(super.getOrgi(request));
TableProperties tb = new TableProperties(); cubeLevel.setCreater(super.getUser(request).getId());
tb.setId(tableid); cubeLevelRes.findById(cubeLevel.getId())
TableProperties t = tablePropertiesRes.findById(tableid); .ifPresent(it -> cubeLevel.setCreatetime(it.getCreatetime()));
cubeLevel.setTablename(t.getTablename()); if (!StringUtils.isBlank(tableid)) {
cubeLevel.setCode(t.getFieldname()); TableProperties tb = new TableProperties();
cubeLevel.setColumname(t.getFieldname()); tb.setId(tableid);
cubeLevel.setTableproperty(tb); TableProperties t = tablePropertiesRes.findById(tableid)
} .orElseThrow(() -> new ResponseStatusException(HttpStatus.NOT_FOUND, String.format("Table properties %s not found", tableid)));
cubeLevelRes.save(cubeLevel) ; cubeLevel.setTablename(t.getTablename());
} cubeLevel.setCode(t.getFieldname());
return request(super.createRequestPageTempletResponse("redirect:/apps/report/cube/detail.html?id="+cubeLevel.getCubeid()+"&dimensionId="+cubeLevel.getDimid())); cubeLevel.setColumname(t.getFieldname());
} cubeLevel.setTableproperty(tb);
@RequestMapping("/fktableid") }
@Menu(type = "report" , subtype = "cubelevel" , admin= true) cubeLevelRes.save(cubeLevel);
public ModelAndView fktableid(ModelMap map , HttpServletRequest request , @Valid String tableid) { }
if(!StringUtils.isBlank(tableid)){ return request(super.createRequestPageTempletResponse("redirect:/apps/report/cube/detail.html?id=" + cubeLevel.getCubeid() + "&dimensionId=" + cubeLevel.getDimid()));
map.put("fktableidList", tablePropertiesRes.findByDbtableid(tableid)); }
}
return request(super.createRequestPageTempletResponse("/apps/business/report/cube/cubelevel/fktableiddiv")); @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"));
}
}

View File

@ -1,121 +1,122 @@
/* /*
* Copyright (C) 2017 优客服-多渠道客服系统 * Copyright (C) 2017 优客服-多渠道客服系统
* Modifications copyright (C) 2018-2019 Chatopera Inc, <https://www.chatopera.com> * Modifications copyright (C) 2018-2019 Chatopera Inc, <https://www.chatopera.com>
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
* You may obtain a copy of the License at * You may obtain a copy of the License at
* *
* http://www.apache.org/licenses/LICENSE-2.0 * http://www.apache.org/licenses/LICENSE-2.0
* *
* Unless required by applicable law or agreed to in writing, software * Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, * distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*/ */
package com.chatopera.cc.controller.apps.report; package com.chatopera.cc.controller.apps.report;
import com.chatopera.cc.controller.Handler; import com.chatopera.cc.controller.Handler;
import com.chatopera.cc.model.CubeMeasure; import com.chatopera.cc.model.CubeMeasure;
import com.chatopera.cc.model.CubeMetadata; import com.chatopera.cc.model.CubeMetadata;
import com.chatopera.cc.persistence.repository.CubeMeasureRepository; import com.chatopera.cc.persistence.repository.CubeMeasureRepository;
import com.chatopera.cc.persistence.repository.CubeMetadataRepository; import com.chatopera.cc.persistence.repository.CubeMetadataRepository;
import com.chatopera.cc.persistence.repository.TablePropertiesRepository; import com.chatopera.cc.persistence.repository.TablePropertiesRepository;
import com.chatopera.cc.util.Menu; import com.chatopera.cc.util.Menu;
import org.apache.commons.lang.StringUtils; import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired; import org.apache.commons.lang.StringUtils;
import org.springframework.stereotype.Controller; import org.springframework.http.HttpStatus;
import org.springframework.ui.ModelMap; import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.ui.ModelMap;
import org.springframework.web.servlet.ModelAndView; import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.server.ResponseStatusException;
import javax.servlet.http.HttpServletRequest; import org.springframework.web.servlet.ModelAndView;
import javax.validation.Valid;
import java.util.List; import javax.servlet.http.HttpServletRequest;
import javax.validation.Valid;
@Controller import java.util.List;
@RequestMapping("/apps/report/cubemeasure")
public class CubeMeasureController extends Handler{ @Controller
@RequestMapping("/apps/report/cubemeasure")
@Autowired @RequiredArgsConstructor
private CubeMeasureRepository cubeMeasureRes; public class CubeMeasureController extends Handler {
@Autowired @org.springframework.lang.NonNull
private TablePropertiesRepository tablePropertiesRes; private final CubeMeasureRepository cubeMeasureRes;
@Autowired @org.springframework.lang.NonNull
private CubeMetadataRepository cubeMetadataRes; private final TablePropertiesRepository tablePropertiesRes;
@RequestMapping("/add") @org.springframework.lang.NonNull
@Menu(type = "report" , subtype = "cubemeasure") private final CubeMetadataRepository cubeMetadataRes;
public ModelAndView cubeMeasureadd(ModelMap map , HttpServletRequest request , @Valid String cubeid) {
map.addAttribute("cubeid", cubeid); @RequestMapping("/add")
List<CubeMetadata> cmList = cubeMetadataRes.findByCubeidAndMtype(cubeid,"0"); @Menu(type = "report", subtype = "cubemeasure")
if(!cmList.isEmpty() && cmList.get(0)!=null) { public ModelAndView cubeMeasureadd(ModelMap map, @Valid String cubeid) {
map.put("fktableidList", tablePropertiesRes.findByDbtableid(cmList.get(0).getTb().getId())); map.addAttribute("cubeid", cubeid);
map.put("table", cmList.get(0).getTb()); List<CubeMetadata> cmList = cubeMetadataRes.findByCubeidAndMtype(cubeid, "0");
} if (!cmList.isEmpty() && cmList.get(0) != null) {
return request(super.createRequestPageTempletResponse("/apps/business/report/cube/cubemeasure/add")); map.put("fktableidList", tablePropertiesRes.findByDbtableid(cmList.get(0).getTb().getId()));
} map.put("table", cmList.get(0).getTb());
}
@RequestMapping("/save") return request(super.createRequestPageTempletResponse("/apps/business/report/cube/cubemeasure/add"));
@Menu(type = "report" , subtype = "cubemeasure" ) }
public ModelAndView cubeMeasuresave(ModelMap map , HttpServletRequest request , @Valid CubeMeasure cubeMeasure) {
if(!StringUtils.isBlank(cubeMeasure.getName())){ @RequestMapping("/save")
cubeMeasure.setOrgi(super.getOrgi(request)); @Menu(type = "report", subtype = "cubemeasure")
cubeMeasure.setCreater(super.getUser(request).getId()); public ModelAndView cubeMeasuresave(HttpServletRequest request, @Valid CubeMeasure cubeMeasure) {
cubeMeasure.setCode(cubeMeasure.getColumname()); if (!StringUtils.isBlank(cubeMeasure.getName())) {
cubeMeasureRes.save(cubeMeasure) ; cubeMeasure.setOrgi(super.getOrgi(request));
} cubeMeasure.setCreater(super.getUser(request).getId());
return request(super.createRequestPageTempletResponse("redirect:/apps/report/cube/detail.html?dimensionId=cubemeasure&id="+cubeMeasure.getCubeid())); cubeMeasure.setCode(cubeMeasure.getColumname());
} cubeMeasureRes.save(cubeMeasure);
}
@RequestMapping("/delete") return request(super.createRequestPageTempletResponse("redirect:/apps/report/cube/detail.html?dimensionId=cubemeasure&id=" + cubeMeasure.getCubeid()));
@Menu(type = "report" , subtype = "cubemeasure" ) }
public ModelAndView quickreplydelete(ModelMap map , HttpServletRequest request , @Valid String id) {
CubeMeasure cubeMeasure = cubeMeasureRes.findOne(id) ; @RequestMapping("/delete")
if(cubeMeasure!=null){ @Menu(type = "report", subtype = "cubemeasure")
cubeMeasureRes.delete(cubeMeasure); public ModelAndView quickreplydelete(@Valid String id) {
} cubeMeasureRes.deleteById(id);
return request(super.createRequestPageTempletResponse("redirect:/apps/report/cube/detail.html?dimensionId=cubemeasure&id="+cubeMeasure.getCubeid())); CubeMeasure cubeMeasure = cubeMeasureRes.findById(id)
} .orElseThrow(() -> new ResponseStatusException(HttpStatus.NOT_FOUND, String.format("Cube measure %s not found", id)));
@RequestMapping("/edit") return request(super.createRequestPageTempletResponse("redirect:/apps/report/cube/detail.html?dimensionId=cubemeasure&id=" + cubeMeasure.getCubeid()));
@Menu(type = "report" , subtype = "cubemeasure" , admin= true) }
public ModelAndView quickreplyedit(ModelMap map , HttpServletRequest request , @Valid String id) {
CubeMeasure cubeMeasure = cubeMeasureRes.findOne(id) ; @RequestMapping("/edit")
map.put("cubemeasure", cubeMeasure) ; @Menu(type = "report", subtype = "cubemeasure", admin = true)
if(cubeMeasure!=null) { public ModelAndView quickreplyedit(ModelMap map, @Valid String id) {
List<CubeMetadata> cmList = cubeMetadataRes.findByCubeidAndMtype(cubeMeasure.getCubeid(),"0"); CubeMeasure cubeMeasure = cubeMeasureRes.findById(id).orElse(null);
if(!cmList.isEmpty() && cmList.get(0)!=null) { map.put("cubemeasure", cubeMeasure);
map.put("fktableidList", tablePropertiesRes.findByDbtableid(cmList.get(0).getTb().getId())); if (cubeMeasure != null) {
map.put("table", cmList.get(0).getTb()); List<CubeMetadata> cmList = cubeMetadataRes.findByCubeidAndMtype(cubeMeasure.getCubeid(), "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/cubemeasure/edit")); map.put("table", cmList.get(0).getTb());
} }
}
@RequestMapping("/update") return request(super.createRequestPageTempletResponse("/apps/business/report/cube/cubemeasure/edit"));
@Menu(type = "report" , subtype = "cubemeasure" , admin= true) }
public ModelAndView quickreplyupdate(ModelMap map , HttpServletRequest request , @Valid CubeMeasure cubeMeasure) {
if(!StringUtils.isBlank(cubeMeasure.getId())){ @RequestMapping("/update")
CubeMeasure temp = cubeMeasureRes.findOne(cubeMeasure.getId()) ; @Menu(type = "report", subtype = "cubemeasure", admin = true)
cubeMeasure.setOrgi(super.getOrgi(request)); public ModelAndView quickreplyupdate(HttpServletRequest request, @Valid CubeMeasure cubeMeasure) {
cubeMeasure.setCreater(super.getUser(request).getId()); if (!StringUtils.isBlank(cubeMeasure.getId())) {
if(temp!=null){ cubeMeasure.setOrgi(super.getOrgi(request));
cubeMeasure.setCreatetime(temp.getCreatetime()); cubeMeasure.setCreater(super.getUser(request).getId());
} cubeMeasureRes.findById(cubeMeasure.getId()).ifPresent(temp -> cubeMeasure.setCreatetime(temp.getCreatetime()));
cubeMeasure.setCode(cubeMeasure.getColumname()); cubeMeasure.setCode(cubeMeasure.getColumname());
cubeMeasureRes.save(cubeMeasure) ; cubeMeasureRes.save(cubeMeasure);
} }
return request(super.createRequestPageTempletResponse("redirect:/apps/report/cube/detail.html?dimensionId=cubemeasure&id="+cubeMeasure.getCubeid())); return request(super.createRequestPageTempletResponse("redirect:/apps/report/cube/detail.html?dimensionId=cubemeasure&id=" + cubeMeasure.getCubeid()));
} }
@RequestMapping("/fktableid")
@Menu(type = "report" , subtype = "cubemeasure" , admin= true) @RequestMapping("/fktableid")
public ModelAndView fktableid(ModelMap map , HttpServletRequest request , @Valid String tableid) { @Menu(type = "report", subtype = "cubemeasure", admin = true)
if(!StringUtils.isBlank(tableid)){ public ModelAndView fktableid(ModelMap map, @Valid String tableid) {
map.put("fktableidList", tablePropertiesRes.findByDbtableid(tableid)); if (!StringUtils.isBlank(tableid)) {
} map.put("fktableidList", tablePropertiesRes.findByDbtableid(tableid));
return request(super.createRequestPageTempletResponse("/apps/business/report/cube/cubemeasure/fktableiddiv")); }
} return request(super.createRequestPageTempletResponse("/apps/business/report/cube/cubemeasure/fktableiddiv"));
} }
}

View File

@ -1,124 +1,126 @@
/* /*
* Copyright (C) 2017 优客服-多渠道客服系统 * Copyright (C) 2017 优客服-多渠道客服系统
* Modifications copyright (C) 2018-2019 Chatopera Inc, <https://www.chatopera.com> * Modifications copyright (C) 2018-2019 Chatopera Inc, <https://www.chatopera.com>
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
* You may obtain a copy of the License at * You may obtain a copy of the License at
* *
* http://www.apache.org/licenses/LICENSE-2.0 * http://www.apache.org/licenses/LICENSE-2.0
* *
* Unless required by applicable law or agreed to in writing, software * Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, * distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*/ */
package com.chatopera.cc.controller.apps.report; package com.chatopera.cc.controller.apps.report;
import com.chatopera.cc.controller.Handler; import com.chatopera.cc.controller.Handler;
import com.chatopera.cc.model.CubeLevel; import com.chatopera.cc.model.CubeLevel;
import com.chatopera.cc.model.CubeMetadata; import com.chatopera.cc.model.CubeMetadata;
import com.chatopera.cc.model.Dimension; import com.chatopera.cc.model.Dimension;
import com.chatopera.cc.persistence.repository.CubeLevelRepository; import com.chatopera.cc.persistence.repository.CubeLevelRepository;
import com.chatopera.cc.persistence.repository.CubeMetadataRepository; import com.chatopera.cc.persistence.repository.CubeMetadataRepository;
import com.chatopera.cc.persistence.repository.DimensionRepository; import com.chatopera.cc.persistence.repository.DimensionRepository;
import com.chatopera.cc.persistence.repository.TablePropertiesRepository; import com.chatopera.cc.persistence.repository.TablePropertiesRepository;
import com.chatopera.cc.util.Menu; import com.chatopera.cc.util.Menu;
import org.apache.commons.lang.StringUtils; import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired; import org.apache.commons.lang.StringUtils;
import org.springframework.stereotype.Controller; import org.springframework.http.HttpStatus;
import org.springframework.ui.ModelMap; import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.ui.ModelMap;
import org.springframework.web.servlet.ModelAndView; import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.server.ResponseStatusException;
import javax.servlet.http.HttpServletRequest; import org.springframework.web.servlet.ModelAndView;
import javax.validation.Valid;
import java.util.List; import javax.servlet.http.HttpServletRequest;
import javax.validation.Valid;
@Controller import java.util.List;
@RequestMapping("/apps/report/dimension")
public class DimensionController extends Handler{ @Controller
@RequestMapping("/apps/report/dimension")
@Autowired @RequiredArgsConstructor
private DimensionRepository dimensionRes; public class DimensionController extends Handler {
@Autowired @org.springframework.lang.NonNull
private CubeLevelRepository cubeLevelRes; private final DimensionRepository dimensionRes;
@Autowired @org.springframework.lang.NonNull
private CubeMetadataRepository cubeMetadataRes; private final CubeLevelRepository cubeLevelRes;
@Autowired @org.springframework.lang.NonNull
private TablePropertiesRepository tablePropertiesRes; private final CubeMetadataRepository cubeMetadataRes;
@RequestMapping("/add") @org.springframework.lang.NonNull
@Menu(type = "report" , subtype = "dimension") private final TablePropertiesRepository tablePropertiesRes;
public ModelAndView dimensionadd(ModelMap map , HttpServletRequest request , @Valid String cubeid) {
map.addAttribute("cubeid", cubeid); @RequestMapping("/add")
map.addAttribute("fkfieldList",cubeMetadataRes.findByCubeidAndMtype(cubeid,"0")); @Menu(type = "report", subtype = "dimension")
map.addAttribute("fktableList",cubeMetadataRes.findByCubeidAndMtypeNot(cubeid,"0")); public ModelAndView dimensionadd(ModelMap map, @Valid String cubeid) {
return request(super.createRequestPageTempletResponse("/apps/business/report/cube/dimension/add")); map.addAttribute("cubeid", cubeid);
} map.addAttribute("fkfieldList", cubeMetadataRes.findByCubeidAndMtype(cubeid, "0"));
map.addAttribute("fktableList", cubeMetadataRes.findByCubeidAndMtypeNot(cubeid, "0"));
@RequestMapping("/save") return request(super.createRequestPageTempletResponse("/apps/business/report/cube/dimension/add"));
@Menu(type = "report" , subtype = "dimension" ) }
public ModelAndView dimensionsave(ModelMap map , HttpServletRequest request , @Valid Dimension dimension) {
if(!StringUtils.isBlank(dimension.getName())){ @RequestMapping("/save")
dimension.setOrgi(super.getOrgi(request)); @Menu(type = "report", subtype = "dimension")
dimension.setCreater(super.getUser(request).getId()); public ModelAndView dimensionsave(HttpServletRequest request, @Valid Dimension dimension) {
dimensionRes.save(dimension) ; if (!StringUtils.isBlank(dimension.getName())) {
} dimension.setOrgi(super.getOrgi(request));
return request(super.createRequestPageTempletResponse("redirect:/apps/report/cube/detail.html?id="+dimension.getCubeid()+"&dimensionId="+dimension.getId())); dimension.setCreater(super.getUser(request).getId());
} dimensionRes.save(dimension);
}
@RequestMapping("/delete") return request(super.createRequestPageTempletResponse("redirect:/apps/report/cube/detail.html?id=" + dimension.getCubeid() + "&dimensionId=" + dimension.getId()));
@Menu(type = "report" , subtype = "dimension" ) }
public ModelAndView quickreplydelete(ModelMap map , HttpServletRequest request , @Valid String id) {
Dimension dimension = dimensionRes.findOne(id) ; @RequestMapping("/delete")
if(dimension!=null){ @Menu(type = "report", subtype = "dimension")
dimensionRes.delete(dimension); public ModelAndView quickreplydelete(HttpServletRequest request, @Valid String id) {
List<CubeLevel> cubeLevelList = cubeLevelRes.findByOrgiAndDimid(super.getOrgi(request), id); Dimension dimension = dimensionRes.findById(id)
if(!cubeLevelList.isEmpty()) { .orElseThrow(() -> new ResponseStatusException(HttpStatus.NOT_FOUND, String.format("Dimension %s not found", id)));
cubeLevelRes.delete(cubeLevelList); dimensionRes.delete(dimension);
} List<CubeLevel> cubeLevelList = cubeLevelRes.findByOrgiAndDimid(super.getOrgi(request), id);
} if (!cubeLevelList.isEmpty()) {
return request(super.createRequestPageTempletResponse("redirect:/apps/report/cube/detail.html?id="+dimension.getCubeid())); cubeLevelRes.deleteAll(cubeLevelList);
} }
@RequestMapping("/edit") return request(super.createRequestPageTempletResponse("redirect:/apps/report/cube/detail.html?id=" + dimension.getCubeid()));
@Menu(type = "report" , subtype = "dimension" , admin= true) }
public ModelAndView quickreplyedit(ModelMap map , HttpServletRequest request , @Valid String id) {
Dimension dimension = dimensionRes.findOne(id) ; @RequestMapping("/edit")
map.put("dimension", dimension) ; @Menu(type = "report", subtype = "dimension", admin = true)
String cubeid = dimension.getCubeid(); public ModelAndView quickreplyedit(ModelMap map, @Valid String id) {
map.addAttribute("cubeid", cubeid); Dimension dimension = dimensionRes.findById(id)
map.addAttribute("fkfieldList",cubeMetadataRes.findByCubeidAndMtype(cubeid,"0")); .orElseThrow(() -> new ResponseStatusException(HttpStatus.NOT_FOUND, String.format("Dimension %s not found", id)));
List<CubeMetadata> fktableList = cubeMetadataRes.findByCubeidAndMtypeNot(cubeid,"0"); map.put("dimension", dimension);
map.addAttribute("fktableList",fktableList); String cubeid = dimension.getCubeid();
map.put("fktableidList", tablePropertiesRes.findByDbtableid(dimension.getFktable())); map.addAttribute("cubeid", cubeid);
return request(super.createRequestPageTempletResponse("/apps/business/report/cube/dimension/edit")); map.addAttribute("fkfieldList", cubeMetadataRes.findByCubeidAndMtype(cubeid, "0"));
} List<CubeMetadata> fktableList = cubeMetadataRes.findByCubeidAndMtypeNot(cubeid, "0");
map.addAttribute("fktableList", fktableList);
@RequestMapping("/update") map.put("fktableidList", tablePropertiesRes.findByDbtableid(dimension.getFktable()));
@Menu(type = "report" , subtype = "dimension" , admin= true) return request(super.createRequestPageTempletResponse("/apps/business/report/cube/dimension/edit"));
public ModelAndView quickreplyupdate(ModelMap map , HttpServletRequest request , @Valid Dimension dimension) { }
if(!StringUtils.isBlank(dimension.getId())){
Dimension temp = dimensionRes.findOne(dimension.getId()) ; @RequestMapping("/update")
dimension.setOrgi(super.getOrgi(request)); @Menu(type = "report", subtype = "dimension", admin = true)
dimension.setCreater(super.getUser(request).getId()); public ModelAndView quickreplyupdate(HttpServletRequest request, @Valid Dimension dimension) {
if(temp!=null){ if (!StringUtils.isBlank(dimension.getId())) {
dimension.setCreatetime(temp.getCreatetime()); dimension.setOrgi(super.getOrgi(request));
} dimension.setCreater(super.getUser(request).getId());
dimensionRes.save(dimension) ; 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())); }
} 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) { @RequestMapping("/fktableid")
if(!StringUtils.isBlank(tableid)){ @Menu(type = "report", subtype = "dimension", admin = true)
map.put("fktableidList", tablePropertiesRes.findByDbtableid(tableid)); public ModelAndView fktableid(ModelMap map, @Valid String tableid) {
} if (!StringUtils.isBlank(tableid)) {
return request(super.createRequestPageTempletResponse("/apps/business/report/cube/dimension/fktableiddiv")); map.put("fktableidList", tablePropertiesRes.findByDbtableid(tableid));
} }
} return request(super.createRequestPageTempletResponse("/apps/business/report/cube/dimension/fktableiddiv"));
}
}

View File

@ -1,35 +1,35 @@
/* /*
* Copyright (C) 2017 优客服-多渠道客服系统 * Copyright (C) 2017 优客服-多渠道客服系统
* Modifications copyright (C) 2018-2019 Chatopera Inc, <https://www.chatopera.com> * Modifications copyright (C) 2018-2019 Chatopera Inc, <https://www.chatopera.com>
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
* You may obtain a copy of the License at * You may obtain a copy of the License at
* *
* http://www.apache.org/licenses/LICENSE-2.0 * http://www.apache.org/licenses/LICENSE-2.0
* *
* Unless required by applicable law or agreed to in writing, software * Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, * distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*/ */
package com.chatopera.cc.persistence.repository; package com.chatopera.cc.persistence.repository;
import com.chatopera.cc.model.TableProperties; import com.chatopera.cc.model.TableProperties;
import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.data.jpa.repository.JpaRepository;
import java.util.List; import java.util.List;
public interface TablePropertiesRepository extends JpaRepository<TableProperties, String>{ public interface TablePropertiesRepository extends JpaRepository<TableProperties, String> {
TableProperties findById(String id); // TableProperties findById(String id);
List<TableProperties> findByDbtableid(String dbtableid) ; List<TableProperties> findByDbtableid(String dbtableid);
List<TableProperties> findByTablename(String tablename) ; List<TableProperties> findByTablename(String tablename);
List<TableProperties> findBySecfield(boolean secfield) ; List<TableProperties> findBySecfield(boolean secfield);
TableProperties findByTablenameAndFieldname(String tablename, String fieldname) ; // TableProperties findByTablenameAndFieldname(String tablename, String fieldname) ;
} }