|
|
@@ -3,20 +3,22 @@ package com.uas.kanban.service.impl;
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
import com.uas.kanban.annotation.NotEmpty;
|
|
|
import com.uas.kanban.base.BaseService;
|
|
|
-import com.uas.kanban.dao.*;
|
|
|
+import com.uas.kanban.dao.KanbanDao;
|
|
|
+import com.uas.kanban.dao.PanelDao;
|
|
|
+import com.uas.kanban.dao.PanelInstanceDao;
|
|
|
+import com.uas.kanban.dao.UserPanelDao;
|
|
|
import com.uas.kanban.exception.OperationException;
|
|
|
import com.uas.kanban.model.*;
|
|
|
-import com.uas.kanban.service.KanbanService;
|
|
|
import com.uas.kanban.service.PanelInstanceService;
|
|
|
import com.uas.kanban.service.ParameterService;
|
|
|
import com.uas.kanban.support.DataSourceManager;
|
|
|
import com.uas.kanban.support.KanbanParser;
|
|
|
+import com.uas.kanban.support.SystemSession;
|
|
|
import com.uas.kanban.util.CollectionUtils;
|
|
|
import com.uas.kanban.util.ObjectUtils;
|
|
|
import com.uas.kanban.util.StringUtils;
|
|
|
import me.chyxion.jdbc.NewbieJdbcSupport;
|
|
|
import org.dom4j.DocumentException;
|
|
|
-import org.mongodb.morphia.query.Query;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
@@ -45,13 +47,7 @@ public class PanelInstanceServiceImpl extends BaseService<PanelInstance> impleme
|
|
|
private KanbanDao kanbanDao;
|
|
|
|
|
|
@Autowired
|
|
|
- private ParameterDao parameterDao;
|
|
|
-
|
|
|
- @Autowired
|
|
|
- private DataSourceDao dataSourceDao;
|
|
|
-
|
|
|
- @Autowired
|
|
|
- private KanbanService kanbanService;
|
|
|
+ private UserPanelDao userPanelDao;
|
|
|
|
|
|
@Autowired
|
|
|
private ParameterService parameterService;
|
|
|
@@ -95,7 +91,7 @@ public class PanelInstanceServiceImpl extends BaseService<PanelInstance> impleme
|
|
|
* @return 生成的参数
|
|
|
*/
|
|
|
private List<Parameter> generateParameters(@NotEmpty("panelInstance") PanelInstance panelInstance) {
|
|
|
- String panelCode = panelInstance.getPanelCode();
|
|
|
+ String panelCode = userPanelDao.checkExist(panelInstance.getUserPanelCode()).getPanelCode();
|
|
|
Panel panel = panelDao.checkExist(panelCode);
|
|
|
String dataSourceCode = panel.getDataSourceCode();
|
|
|
List<Parameter> parameters = parameterService.getByPanelCode(panelCode);
|
|
|
@@ -166,47 +162,21 @@ public class PanelInstanceServiceImpl extends BaseService<PanelInstance> impleme
|
|
|
return update(json);
|
|
|
}
|
|
|
|
|
|
- @Override
|
|
|
- public int deleteAll() throws OperationException {
|
|
|
- // 需要检查实例是否是自动生成的,难以检查
|
|
|
- throw new OperationException("不支持的操作");
|
|
|
- }
|
|
|
-
|
|
|
- @Override
|
|
|
- public int deleteOne(@NotEmpty("code") String code) throws OperationException {
|
|
|
- PanelInstance panelInstance = panelInstanceDao.findOne(code);
|
|
|
- if (panelInstance != null) {
|
|
|
- Boolean autoGenerated = panelInstance.getAutoGenerated();
|
|
|
- if (autoGenerated != null && autoGenerated) {
|
|
|
- throw new OperationException("不可删除该实例");
|
|
|
- }
|
|
|
- }
|
|
|
- return super.deleteOne(code);
|
|
|
- }
|
|
|
-
|
|
|
- @Override
|
|
|
- public int delete(@NotEmpty("codes") List<String> codes) throws OperationException {
|
|
|
- List<PanelInstance> panelInstances = panelInstanceDao.findIn(codes);
|
|
|
- if (CollectionUtils.isEmpty(panelInstances)) {
|
|
|
- return 0;
|
|
|
- }
|
|
|
- for (PanelInstance panelInstance : panelInstances) {
|
|
|
- Boolean autoGenerated = panelInstance.getAutoGenerated();
|
|
|
- if (autoGenerated != null && autoGenerated) {
|
|
|
- throw new OperationException("不可删除实例:" + panelInstance.getCode());
|
|
|
- }
|
|
|
- }
|
|
|
- return super.delete(codes);
|
|
|
- }
|
|
|
-
|
|
|
@Override
|
|
|
public Map<String, Object> parseData(@NotEmpty("code") String code, String kanbanCode) {
|
|
|
PanelInstance panelInstance = panelInstanceDao.checkExist(code);
|
|
|
- Panel panel = panelDao.checkExist(panelInstance.getPanelCode());
|
|
|
- List<String> enabledKanbanCodes = kanbanService.getEnabledCodesByPanelCode(panel.getCode());
|
|
|
- if (CollectionUtils.isEmpty(enabledKanbanCodes)) {
|
|
|
+ Panel panel = panelDao.checkExist(userPanelDao.checkExist(panelInstance.getUserPanelCode()).getPanelCode());
|
|
|
+ List<PanelInstance.RelatedKanban> relatedKanbans = panelInstance.getRelatedKanbans();
|
|
|
+ if (CollectionUtils.isEmpty(relatedKanbans)) {
|
|
|
throw new IllegalStateException("面板下没有看板");
|
|
|
}
|
|
|
+ // 只保留已启用的看板
|
|
|
+ List<String> enabledKanbanCodes = new ArrayList<>();
|
|
|
+ for (PanelInstance.RelatedKanban relatedKanban : relatedKanbans) {
|
|
|
+ if (relatedKanban.getEnabled() != null && relatedKanban.getEnabled()) {
|
|
|
+ enabledKanbanCodes.add(relatedKanban.getCode());
|
|
|
+ }
|
|
|
+ }
|
|
|
// 如果指定了看板,则解析该看板,否则解析该面板下的第一个看板
|
|
|
if (!StringUtils.isEmpty(kanbanCode)) {
|
|
|
if (!enabledKanbanCodes.contains(kanbanCode)) {
|
|
|
@@ -239,7 +209,7 @@ public class PanelInstanceServiceImpl extends BaseService<PanelInstance> impleme
|
|
|
Map<String, Object> result = new HashMap<>();
|
|
|
Map<String, Object> instance = new HashMap<>();
|
|
|
instance.put("parameters", parameters);
|
|
|
- instance.put("kanbanCodes", enabledKanbanCodes);
|
|
|
+ instance.put("enabledKanbanCodes", enabledKanbanCodes);
|
|
|
instance.put("display", panel.getDisplay());
|
|
|
instance.put("switchFrequency", panelInstance.getSwitchFrequency());
|
|
|
instance.put("refreshFrequency", panelInstance.getRefreshFrequency());
|
|
|
@@ -252,42 +222,43 @@ public class PanelInstanceServiceImpl extends BaseService<PanelInstance> impleme
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
- public int deleteByPanelCodes(@NotEmpty("panelCodes") List<String> panelCodes) {
|
|
|
- Query<PanelInstance> query = panelInstanceDao.createQuery().field("panelCode").in(panelCodes);
|
|
|
- return panelInstanceDao.delete(query);
|
|
|
- }
|
|
|
-
|
|
|
- @Override
|
|
|
- public List<PanelInstance> getByPanelCode(@NotEmpty("panelCode") String panelCode) {
|
|
|
+ public PanelInstance getByPanelCode(@NotEmpty("panelCode") String panelCode) {
|
|
|
panelDao.checkExist(panelCode);
|
|
|
- return panelInstanceDao.findListBy("panelCode", Collections.singletonList(panelCode));
|
|
|
- }
|
|
|
-
|
|
|
- @Override
|
|
|
- public List<PanelInstance> generateInstances(@NotEmpty("userCodes") List<String> userCodes, @NotEmpty("panelCodes") List<String> panelCodes) {
|
|
|
- List<PanelInstance> panelInstances = new ArrayList<>();
|
|
|
- for (String panelCode : panelCodes) {
|
|
|
- Panel panel = panelDao.checkExist(panelCode);
|
|
|
- PanelInstance panelInstance = new PanelInstance();
|
|
|
- panelInstance.setName(panel.getName());
|
|
|
- panelInstance.setIconCls(panel.getIconCls());
|
|
|
- panelInstance.setAutoGenerated(true);
|
|
|
- panelInstance.setPanelCode(panelCode);
|
|
|
- initSwitchFrequence(panelInstance);
|
|
|
- panelInstance.toParameters(generateParameters(panelInstance));
|
|
|
- for (String userCode : userCodes) {
|
|
|
- // TODO generateInstances
|
|
|
- // TODO implement batch save
|
|
|
- try {
|
|
|
- PanelInstance panelInstanceClone = ObjectUtils.clone(panelInstance);
|
|
|
- panelInstanceClone.setUserCode(userCode);
|
|
|
- panelInstances.add(panelInstanceDao.save(panelInstanceClone));
|
|
|
- } catch (ClassNotFoundException | IOException e) {
|
|
|
- throw new IllegalStateException("深克隆对象时失败", e);
|
|
|
+ PanelInstance panelInstance = panelInstanceDao.findByPanelCode(panelCode);
|
|
|
+ if (panelInstance == null) {
|
|
|
+ User user = SystemSession.getUser();
|
|
|
+ String userCode = user.getCode();
|
|
|
+ UserPanel userPanel = userPanelDao.findByUserCodeAndPanelCode(userCode, panelCode);
|
|
|
+ // 管理员可以查看所有面板,不必先分配,但是想要保存实例,就需要先建立关联
|
|
|
+ if (userPanel == null) {
|
|
|
+ if (user.getRole() == User.Role.Admin) {
|
|
|
+ userPanel = userPanelDao.save(new UserPanel(userCode, panelCode));
|
|
|
+ }else{
|
|
|
+ throw new IllegalArgumentException("用户未分配该面板");
|
|
|
}
|
|
|
}
|
|
|
+ panelInstance = generateInstance(userPanel);
|
|
|
}
|
|
|
- return panelInstances;
|
|
|
+ return panelInstance;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 根据指定的用户面板生成面板实例
|
|
|
+ *
|
|
|
+ * @param userPanel 所指定的用户面板
|
|
|
+ * @return 面板实例
|
|
|
+ */
|
|
|
+ private PanelInstance generateInstance(@NotEmpty("userPanel") UserPanel userPanel) {
|
|
|
+ String panelCode = userPanel.getPanelCode();
|
|
|
+ Panel panel = panelDao.checkExist(panelCode);
|
|
|
+ PanelInstance panelInstance = new PanelInstance();
|
|
|
+ panelInstance.setUserPanelCode(userPanel.getCode());
|
|
|
+ initSwitchFrequence(panelInstance);
|
|
|
+ panelInstance.toParameters(generateParameters(panelInstance));
|
|
|
+ List<Kanban> kanbans = kanbanDao.findByPanelCode(panelCode);
|
|
|
+ panelInstance.initKanbanCodes(kanbans);
|
|
|
+ panelInstanceDao.save(panelInstance);
|
|
|
+ return panelInstance;
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
@@ -297,7 +268,7 @@ public class PanelInstanceServiceImpl extends BaseService<PanelInstance> impleme
|
|
|
*/
|
|
|
private void initSwitchFrequence(@NotEmpty("panelInstance") PanelInstance panelInstance)
|
|
|
throws IllegalArgumentException {
|
|
|
- Panel panel = panelDao.checkExist(panelInstance.getPanelCode());
|
|
|
+ Panel panel = panelDao.checkExist(userPanelDao.checkExist(panelInstance.getUserPanelCode()).getPanelCode());
|
|
|
switch (panel.getDisplay()) {
|
|
|
case AutoSwitch:
|
|
|
if (panelInstance.getSwitchFrequency() == null) {
|
|
|
@@ -312,10 +283,4 @@ public class PanelInstanceServiceImpl extends BaseService<PanelInstance> impleme
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- @Override
|
|
|
- public PanelInstance saveToDesktop(@NotEmpty("json") String json) {
|
|
|
- // TODO save to desktop
|
|
|
- return null;
|
|
|
- }
|
|
|
-
|
|
|
}
|