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:
parent
f6a09e8c48
commit
192c664db0
@ -1,136 +1,136 @@
|
||||
/*
|
||||
* Copyright (C) 2017 优客服-多渠道客服系统
|
||||
* Modifications copyright (C) 2018-2019 Chatopera Inc, <https://www.chatopera.com>
|
||||
*
|
||||
* 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<ContextRefreshedEvent> {
|
||||
|
||||
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<SysDic> sysDicList = sysDicRes.findAll();
|
||||
Map<String, List<SysDic>> rootDictItems = new HashMap<>(); // 关联根词典及其子项
|
||||
Map<String, SysDic> rootDics = new HashMap<>();
|
||||
Set<String> 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<SysDic>());
|
||||
}
|
||||
rootDictItems.get(dic.getDicid()).add(dic);
|
||||
}
|
||||
}
|
||||
|
||||
// 更新缓存
|
||||
// TODO 集群时注意!!!
|
||||
// 此处为长时间的操作,如果在一个集群中,会操作共享内容,非常不可靠
|
||||
// 所以,当前代码不支持集群,需要解决启动上的这个问题!
|
||||
|
||||
// 存储根词典 TODO 此处只考虑了系统默认租户
|
||||
cache.putSysDicByOrgi(new ArrayList<>(rootDics.values()), MainContext.SYSTEM_ORGI);
|
||||
|
||||
for (final Map.Entry<String, List<SysDic>> 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<BlackEntity> 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.");
|
||||
}
|
||||
}
|
||||
}
|
||||
/*
|
||||
* Copyright (C) 2017 优客服-多渠道客服系统
|
||||
* Modifications copyright (C) 2018-2019 Chatopera Inc, <https://www.chatopera.com>
|
||||
*
|
||||
* 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<ContextRefreshedEvent> {
|
||||
|
||||
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<SysDic> sysDicList = sysDicRes.findAll();
|
||||
Map<String, List<SysDic>> rootDictItems = new HashMap<>(); // 关联根词典及其子项
|
||||
Map<String, SysDic> rootDics = new HashMap<>();
|
||||
Set<String> 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<SysDic>());
|
||||
}
|
||||
rootDictItems.get(dic.getDicid()).add(dic);
|
||||
}
|
||||
}
|
||||
|
||||
// 更新缓存
|
||||
// TODO 集群时注意!!!
|
||||
// 此处为长时间的操作,如果在一个集群中,会操作共享内容,非常不可靠
|
||||
// 所以,当前代码不支持集群,需要解决启动上的这个问题!
|
||||
|
||||
// 存储根词典 TODO 此处只考虑了系统默认租户
|
||||
cache.putSysDicByOrgi(new ArrayList<>(rootDics.values()), MainContext.SYSTEM_ORGI);
|
||||
|
||||
for (final Map.Entry<String, List<SysDic>> 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<BlackEntity> 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.");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -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<TableProperties>());
|
||||
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())) {
|
||||
|
@ -1,161 +1,167 @@
|
||||
/*
|
||||
* Copyright (C) 2017 优客服-多渠道客服系统
|
||||
* Modifications copyright (C) 2018-2019 Chatopera Inc, <https://www.chatopera.com>
|
||||
*
|
||||
* 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<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" )
|
||||
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<CubeMetadata> 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"));
|
||||
}
|
||||
}
|
||||
/*
|
||||
* Copyright (C) 2017 优客服-多渠道客服系统
|
||||
* Modifications copyright (C) 2018-2019 Chatopera Inc, <https://www.chatopera.com>
|
||||
*
|
||||
* 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<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")
|
||||
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<CubeMetadata> 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"));
|
||||
}
|
||||
}
|
||||
|
@ -1,121 +1,122 @@
|
||||
/*
|
||||
* Copyright (C) 2017 优客服-多渠道客服系统
|
||||
* Modifications copyright (C) 2018-2019 Chatopera Inc, <https://www.chatopera.com>
|
||||
*
|
||||
* 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<CubeMetadata> 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<CubeMetadata> 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"));
|
||||
}
|
||||
}
|
||||
/*
|
||||
* Copyright (C) 2017 优客服-多渠道客服系统
|
||||
* Modifications copyright (C) 2018-2019 Chatopera Inc, <https://www.chatopera.com>
|
||||
*
|
||||
* 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<CubeMetadata> 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<CubeMetadata> 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"));
|
||||
}
|
||||
}
|
||||
|
@ -1,124 +1,126 @@
|
||||
/*
|
||||
* Copyright (C) 2017 优客服-多渠道客服系统
|
||||
* Modifications copyright (C) 2018-2019 Chatopera Inc, <https://www.chatopera.com>
|
||||
*
|
||||
* 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<CubeLevel> 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<CubeMetadata> 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"));
|
||||
}
|
||||
}
|
||||
/*
|
||||
* Copyright (C) 2017 优客服-多渠道客服系统
|
||||
* Modifications copyright (C) 2018-2019 Chatopera Inc, <https://www.chatopera.com>
|
||||
*
|
||||
* 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<CubeLevel> 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<CubeMetadata> 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"));
|
||||
}
|
||||
}
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -1,35 +1,35 @@
|
||||
/*
|
||||
* Copyright (C) 2017 优客服-多渠道客服系统
|
||||
* Modifications copyright (C) 2018-2019 Chatopera Inc, <https://www.chatopera.com>
|
||||
*
|
||||
* 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, String>{
|
||||
|
||||
TableProperties findById(String id);
|
||||
|
||||
List<TableProperties> findByDbtableid(String dbtableid) ;
|
||||
|
||||
List<TableProperties> findByTablename(String tablename) ;
|
||||
|
||||
List<TableProperties> findBySecfield(boolean secfield) ;
|
||||
|
||||
TableProperties findByTablenameAndFieldname(String tablename, String fieldname) ;
|
||||
}
|
||||
/*
|
||||
* Copyright (C) 2017 优客服-多渠道客服系统
|
||||
* Modifications copyright (C) 2018-2019 Chatopera Inc, <https://www.chatopera.com>
|
||||
*
|
||||
* 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, String> {
|
||||
|
||||
// TableProperties findById(String id);
|
||||
|
||||
List<TableProperties> findByDbtableid(String dbtableid);
|
||||
|
||||
List<TableProperties> findByTablename(String tablename);
|
||||
|
||||
List<TableProperties> findBySecfield(boolean secfield);
|
||||
|
||||
// TableProperties findByTablenameAndFieldname(String tablename, String fieldname) ;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user