Commit ddd09f71 authored by linruibiao's avatar linruibiao

接口编写

parent d1be6cdc
package com.syc.slm.common.core.util;
import com.syc.slm.common.core.constant.SlmConstants;
import com.syc.slm.slmbi.exception.SysException;
import com.syc.slm.slmbi.function.Action0;
......@@ -18,11 +19,11 @@ public final class NetResponseUtils {
return R.ok(x.get());
} catch (Exception ex) {
ex.printStackTrace();
if ((ex.getCause() instanceof SysException)) {
SysException e = (SysException)ex.getCause();
if (ex instanceof SysException) {
SysException e = (SysException) ex;
return R.failed(e.getMsg());
}
return R.failed(ex.getMessage());
return R.failed("出错啦请联系管理员",ex.toString());
}
}
......@@ -32,7 +33,11 @@ public final class NetResponseUtils {
return R.ok();
} catch (Exception ex) {
ex.printStackTrace();
return R.failed(ex.getMessage());
if (ex instanceof SysException) {
SysException e = (SysException) ex;
return R.failed(e.getMsg());
}
return R.bad("出错啦请联系管理员",ex.toString());
}
}
}
......@@ -53,6 +53,11 @@ public class R<T> implements Serializable {
@ApiModelProperty(value = "返回信息")
private String msg;
@Getter
@Setter
@ApiModelProperty(value = "调式异常")
private String debugMsg;
@Getter
@Setter
@ApiModelProperty(value = "数据")
......@@ -77,7 +82,9 @@ public class R<T> implements Serializable {
public static <T> R<T> failed(String msg) {
return restResult(null, CommonConstants.FAIL, msg);
}
public static <T> R<T> failed(String msg,String debugMsg) {
return restResult(null, CommonConstants.FAIL, msg,debugMsg);
}
public static <T> R<T> failed(T data) {
return restResult(data, CommonConstants.FAIL, null);
}
......@@ -86,6 +93,10 @@ public class R<T> implements Serializable {
return restResult(data, CommonConstants.FAIL, msg);
}
public static <T> R<T> bad(String msg,String debugMsg) {
return failed(msg,debugMsg);
}
private static <T> R<T> restResult(T data, int code, String msg) {
R<T> apiResult = new R<>();
apiResult.setCode(code);
......@@ -93,5 +104,13 @@ public class R<T> implements Serializable {
apiResult.setMsg(msg);
return apiResult;
}
private static <T> R<T> restResult(T data, int code, String msg,String debugMsg) {
R<T> apiResult = new R<>();
apiResult.setCode(code);
apiResult.setData(data);
apiResult.setMsg(msg);
apiResult.setDebugMsg(debugMsg);
return apiResult;
}
}
......@@ -18,7 +18,7 @@ import java.util.function.Supplier;
@Component
@Slf4j
public class SysMetaObjectHandler implements MetaObjectHandler {
private static final String ID = "id";
private static final String APP_ID = "appId";
private static final String CREATOR = "creator";
private static final String CREATOR_NAME = "creatorName";
......@@ -33,6 +33,9 @@ public class SysMetaObjectHandler implements MetaObjectHandler {
*/
@Override
public void insertFill(MetaObject metaObject) {
fillValue(metaObject,
ID,
() -> (metaObject.getValue(ID) == null ? IdWorker.get32UUID() : metaObject.getValue(ID)));
fillValue(metaObject,
APP_ID,
() -> (metaObject.getValue(APP_ID) == null ? "68d61d7f990e11eb847e88d7f63cc98f" : metaObject.getValue(APP_ID)));
......
package com.syc.slm.slmbi.controller;
import com.syc.slm.common.core.constant.SlmConstants;
import com.syc.slm.common.core.util.NetResponseUtils;
import com.syc.slm.common.core.util.R;
import com.syc.slm.slmbi.function.Action0;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.ModelAttribute;
import javax.servlet.http.HttpServletRequest;
import java.util.Enumeration;
import java.util.Map;
import java.util.function.Supplier;
/**
......@@ -13,7 +19,15 @@ import java.util.function.Supplier;
* @author : lin
* @date : 2021-04-06 09:09
**/
@Slf4j
public class BaseRestController {
@ModelAttribute
public void onInit(HttpServletRequest request) {
String uri = request.getRequestURI();
log.info("请求url--->>>>" + uri);
Map<String, String[]> parameterMap = request.getParameterMap();
log.info("请求参数--->>>>"+SlmConstants.gson.toJson(parameterMap));
}
R<Object> call(Action0 action) {
return NetResponseUtils.call(action);
}
......
......@@ -30,7 +30,7 @@ public class InstrumentPanelConfigController {
@PostMapping
@ApiOperation("保存仪表板样式以及数据配置")
@ApiImplicitParam(name = "appId", value = "租户id", required = true,dataTypeClass = String.class)
public R<String> saveInstrumentPanelConfig(@PathVariable String appId, InstrumentPanelConfigDTO config) {
public R<String> saveInstrumentPanelConfig(@PathVariable String appId, @RequestBody InstrumentPanelConfigDTO config) {
return R.ok(instrumentPanelConfigService.saveConfig(appId,config));
}
......
......@@ -60,7 +60,7 @@ public class InstrumentPanelController extends BaseRestController {
required = true,
dataTypeClass = Arrays.class),
@ApiImplicitParam(name = "appId", value = "租户id", required = true, dataTypeClass = String.class)})
public R<Object> batchPublish(@PathVariable String appId, @RequestParam List<String> ids) {
public R<List<String>> batchPublish(@PathVariable String appId, @RequestParam List<String> ids) {
return call(() -> instrumentPanelService.batchPublish(ids));
}
......
......@@ -48,7 +48,7 @@ public class InstrumentPanelGroupController extends BaseRestController{
}
@PutMapping
@ApiOperation("更新仪表板分组")
@ApiOperation("更新仪表板分组(一级分组是初始化得,不允许修改,其他分组修改必须传parentId)")
@ApiImplicitParam(name = "appId", value = "租户id", required = true,dataTypeClass = String.class)
public R<String> updateGroup(@PathVariable String appId, @RequestBody InstrumentPanelGroupDTO group) {
return call(()->instrumentPanelGroupService.updateGroup(group,appId));
......
......@@ -36,7 +36,7 @@ public class InstrumentPanelPermissionController extends BaseRestController {
return call(() -> instrumentPanelPermissionService.savePermission(permission));
}
@PutMapping("/{panelId}/to-copy")
@GetMapping("/{panelId}/to-copy")
@ApiOperation("从其他仪表板复制配置")
@ApiImplicitParams({@ApiImplicitParam(name = "appId",
value = "租户id",
......@@ -54,7 +54,7 @@ public class InstrumentPanelPermissionController extends BaseRestController {
value = "租户id",
required = true,
dataTypeClass = String.class),
@ApiImplicitParam(name = "panelId", value = "其他仪表板id", required = true, dataTypeClass = Arrays.class)})
@ApiImplicitParam(name = "panelIds", value = "其他仪表板id", required = true, dataTypeClass = Arrays.class)})
public R<Object> saveCopyToOtherPermission(@PathVariable String appId,
@RequestBody InstrumentPanelPermissionDTO permission,
@RequestParam List<String> panelIds) {
......
......@@ -13,6 +13,7 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import java.util.List;
import java.util.Map;
/**
* @author liangbin
......@@ -57,9 +58,9 @@ public class InstrumentPanelTreeController extends BaseRestController {
@ApiImplicitParam(name = "nodeId", value = "分组id", required = true, dataTypeClass = String.class),
@ApiImplicitParam(name = "name", value = "分组名称或者仪表板名称", dataTypeClass = String.class)})
public R<List<PanelTreeNodeVo>> children(@PathVariable String appId,
@RequestParam("nodeId") String groupId,
@RequestParam("nodeId") String nodeId,
@RequestParam(value = "name", required = false) String name) {
return call(() -> (treeService.children(groupId, name)));
return call(() -> (treeService.children(nodeId, name)));
}
@GetMapping("/children-panel")
......@@ -97,4 +98,15 @@ public class InstrumentPanelTreeController extends BaseRestController {
public R<List<PanelTreeNodeVo>> cite(@PathVariable String appId,@RequestParam(value = "name", required = false) String name) {
return call(() -> (treeService.citeTreeList(appId,name)));
}
@GetMapping("/cite-assembly")
@ApiOperation("复用仪表板树点击组件获取配置(会返回一个map 优先从key为 wait_published 中匹配,如果找不到再从key 为published 中匹配 )")
@ApiImplicitParams({@ApiImplicitParam(name = "appId",
value = "租户id",
required = true,
dataTypeClass = String.class),
@ApiImplicitParam(name = "appId", value = "租户id", required = true, dataTypeClass = String.class),
@ApiImplicitParam(name = "panelId", value = "仪表板id", required = true, dataTypeClass = String.class)})
public R<Map<String,String>> assembly(@PathVariable String appId,@RequestParam(value = "panelId", required = false) String panelId) {
return call(() -> (treeService.assembly(appId,panelId)));
}
}
......@@ -28,37 +28,37 @@ public class BaseEntity<T extends Model<?>> extends Model<T> {
*/
@TableId
@ApiModelProperty(value = "主键")
private String id;
protected String id;
/**
* 租户id
*/
@ApiModelProperty(value = "租户id")
@TableField(fill = FieldFill.INSERT)
private String appId;
protected String appId;
@ApiModelProperty(value = "创建人主键")
@TableField(fill = FieldFill.INSERT)
private String creator;
protected String creator;
@ApiModelProperty(value = "创建人名称")
@TableField(fill = FieldFill.INSERT)
private String creatorName;
protected String creatorName;
@ApiModelProperty(value = "创建时间")
@TableField(fill = FieldFill.INSERT)
private Date createTime;
protected Date createTime;
@ApiModelProperty(value = "修改人主键")
@TableField(fill = FieldFill.UPDATE)
private String updater;
protected String updater;
@ApiModelProperty(value = "修改人名称")
@TableField(fill = FieldFill.UPDATE)
private String updaterName;
protected String updaterName;
@ApiModelProperty(value = "修改时间")
@TableField(fill = FieldFill.UPDATE)
private Date updateTime;
protected Date updateTime;
@ApiModelProperty(value = "状态")
@TableField(fill = FieldFill.INSERT)
private Integer recordStatus;
protected Integer recordStatus;
@ApiModelProperty(value = "描述")
private String description;
protected String description;
@Override
protected Serializable pkVal() {
......
......@@ -18,8 +18,6 @@ import lombok.EqualsAndHashCode;
@EqualsAndHashCode(callSuper=true)
@TableName("instrument_panel")
public class InstrumentPanel extends BaseEntity<InstrumentPanel>{
@ApiModelProperty(value = "仪表板主键")
private String id ;
@ApiModelProperty(value = "仪表板名称")
private String name;
@ApiModelProperty(value = "仪表板归属分组")
......@@ -27,13 +25,13 @@ public class InstrumentPanel extends BaseEntity<InstrumentPanel>{
@ApiModelProperty(value = "访问权限")
private String accessPermission;
@ApiModelProperty(value = "发布状态")
private Integer published;
private String published;
public InstrumentPanel() {
}
public InstrumentPanel(String id, String name, String groupId, String accessPermission, Integer published) {
this.id = id;
public InstrumentPanel(String id, String name, String groupId, String accessPermission, String published) {
super.id=id;
this.name = name;
this.groupId = groupId;
this.accessPermission = accessPermission;
......
......@@ -24,5 +24,5 @@ public class InstrumentPanelConfig extends BaseEntity<InstrumentPanelConfig>{
@ApiModelProperty(value = "仪表板配置详情,包含了样式,数据配置")
private String configDetails;
@ApiModelProperty(value = "发布状态")
private Integer published;
private String published;
}
......@@ -17,7 +17,6 @@ import lombok.EqualsAndHashCode;
@EqualsAndHashCode(callSuper = true)
@ApiModel(value = "仪表板草稿")
public class InstrumentPanelDraft extends BaseEntity<InstrumentPanelDraft> {
private static final long serialVersionUID = 1L;
/**
* 仪表板名字
......
......@@ -17,7 +17,6 @@ import lombok.EqualsAndHashCode;
@EqualsAndHashCode(callSuper = true)
@ApiModel(value = "仪表板权限")
public class InstrumentPanelPermission extends BaseEntity<InstrumentPanelPermission> {
private static final long serialVersionUID = 1L;
/**
* 仪表板id
*/
......@@ -42,5 +41,5 @@ public class InstrumentPanelPermission extends BaseEntity<InstrumentPanelPermiss
* 1代表第一版数据,2代表保存发布再次保存得数据
*/
@ApiModelProperty(value = "1代表第一版数据,2代表保存发布再次保存得数据")
private Integer published;
private String published;
}
......@@ -8,18 +8,18 @@ public enum PublishedStatus {
/**
* 发布
*/
PUBLISHED(1),
PUBLISHED("published"),
/**
* 待发布
*/
WAIT_PUBLISHED(2),
WAIT_PUBLISHED("wait_published"),
/**
* 下线
*/
OFFLINE(3),
DRAFT(4);
public Integer value;
OFFLINE("offline"),
DRAFT("draft");
public String value;
PublishedStatus(Integer v) {
PublishedStatus(String v) {
value = v;
}}
......@@ -7,6 +7,7 @@ import com.syc.slm.slmbi.vo.InstrumentPanelConfigVo;
import javax.validation.constraints.NotNull;
import java.util.List;
import java.util.Map;
/**
* slm-bi
......@@ -53,7 +54,7 @@ public interface InstrumentPanelConfigService extends IService<InstrumentPanelCo
* @param panelId
* @param publishedStatus
*/
void delConfig(@NotNull String panelId,Integer publishedStatus);
void delConfig(@NotNull String panelId,String publishedStatus);
/**
* 根据仪表板详情保存仪表盘配置
......@@ -61,7 +62,7 @@ public interface InstrumentPanelConfigService extends IService<InstrumentPanelCo
* @param configDetails
* @param publishStatus
*/
void savePanelConfig(String panelId,String configDetails,Integer publishStatus);
void savePanelConfig(String panelId,String configDetails,String publishStatus);
/**
* 发布仪表板把对应配置状态修改为发布
......@@ -75,12 +76,18 @@ public interface InstrumentPanelConfigService extends IService<InstrumentPanelCo
* @param publishStatus
* @return
*/
List<InstrumentPanelConfig> getConfigByPanelIdAndPublishStatus(String panelId,Integer publishStatus);
List<InstrumentPanelConfig> getConfigByPanelIdAndPublishStatus(String panelId,String publishStatus);
/**
* 下线仪表盘配置
* @param panelId
* @param publishStatus
*/
void offlineConfig(String panelId, Integer publishStatus);
void offlineConfig(String panelId, String publishStatus);
/**
* 根据仪表id获取仪表板配置
* @param panelId
*/
Map<String,String> getAssemblyConfig(@NotNull String panelId);
}
......@@ -53,15 +53,17 @@ public interface InstrumentPanelPermissionService extends IService<InstrumentPan
/**
* 根据仪表板id删除仪表板权限
* @param panelId
* @param publishStatus
*/
void delPermissionByPanelId(@NonNull String panelId,Integer publishStatus);
void delPermissionByPanelId(@NonNull String panelId,String publishStatus);
/**
* 根据仪表板id获取已经发布的配置
* @param panelId
* @param publishStatus
* @return
*/
List<CustomPermissionVo> getPublishPermissionByPanelId(@NonNull String panelId,@NonNull Integer publishStatus);
List<CustomPermissionVo> getPublishPermissionByPanelId(@NonNull String panelId,@NonNull String publishStatus);
/**
* 根据仪表板详情保存仪表板配置
......@@ -70,7 +72,7 @@ public interface InstrumentPanelPermissionService extends IService<InstrumentPan
* @param accessType
* @param publishStatus
*/
void savePanelPermission(List<CustomPermissionDTO> customPermissions,String panelId,String accessType,Integer publishStatus);
void savePanelPermission(List<CustomPermissionDTO> customPermissions,String panelId,String accessType,String publishStatus);
/**
* 批量发布把对应配置状态更改为发布状态
......@@ -84,7 +86,7 @@ public interface InstrumentPanelPermissionService extends IService<InstrumentPan
* @param publishStatus
* @return
*/
List<InstrumentPanelPermission> getPermissionByPanelIdAndPublishStatus(String panelId, Integer publishStatus);
List<InstrumentPanelPermission> getPermissionByPanelIdAndPublishStatus(String panelId, String publishStatus);
/**
* 下线仪表板对应权限
......
......@@ -43,7 +43,7 @@ public interface InstrumentPanelService extends IService<InstrumentPanel> {
* @param ids
* @return
*/
void batchPublish(List<String> ids);
List<String> batchPublish(List<String> ids);
/**
* 删除仪表板
......
......@@ -3,9 +3,11 @@ package com.syc.slm.slmbi.service;
import com.baomidou.mybatisplus.extension.service.IService;
import com.syc.slm.slmbi.dto.InstrumentPanelAssemblyDTO;
import com.syc.slm.slmbi.entity.InstrumentPanelTree;
import com.syc.slm.slmbi.vo.InstrumentPanelConfigVo;
import com.syc.slm.slmbi.vo.PanelTreeNodeVo;
import java.util.List;
import java.util.Map;
import java.util.Set;
/**
......@@ -104,4 +106,12 @@ public interface InstrumentPanelTreeService extends IService<InstrumentPanelTree
* @return
*/
List<PanelTreeNodeVo> citeTreeList(String appId, String name);
/**
* 点击仪表板组件获取对应配置
* @param appId
* @param panelId
* @return
*/
Map<String, String> assembly(String appId, String panelId);
}
......@@ -5,6 +5,7 @@ import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
import com.baomidou.mybatisplus.core.toolkit.IdWorker;
import com.baomidou.mybatisplus.core.toolkit.ObjectUtils;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.google.common.collect.Maps;
import com.syc.slm.common.core.constant.SlmConstants;
import com.syc.slm.slmbi.dao.InstrumentPanelConfigMapper;
import com.syc.slm.slmbi.dto.InstrumentPanelConfigDTO;
......@@ -62,7 +63,6 @@ public class InstrumentPanelConfigServiceImpl extends ServiceImpl<InstrumentPane
return getInstrumentPanelConfigVo(instrumentPanelId, PublishedStatus.PUBLISHED);
}
//#todo 未确定
@Override
@Transactional(readOnly = true)
public InstrumentPanelConfigVo getConfigByPanelId(String instrumentPanelId) {
......@@ -78,7 +78,7 @@ public class InstrumentPanelConfigServiceImpl extends ServiceImpl<InstrumentPane
InstrumentPanelPermissionDTO permission = config.getPermission();
checkAll(appId, config, permission);
InstrumentPanel panel = panelService.getById(config.getPanelId());
fillPanelProp(permission, panel);
fillPanelProp(permission, panel, PublishedStatus.PUBLISHED.value);
log.info("删除仪表板配置详情");
delConfig(config.getPanelId(), null);
log.info("保存配置详情");
......@@ -87,23 +87,27 @@ public class InstrumentPanelConfigServiceImpl extends ServiceImpl<InstrumentPane
log.info("删除仪表板权限信息");
permissionService.delPermissionByPanelId(config.getPanelId(), null);
log.info("保存权限信息");
permissionService.savePanelPermission(permission.getCustomPermissions(),
panel.getId(),
permission.getAccessType(),
PublishedStatus.PUBLISHED.value);
permissionService.savePanelPermission(permission.getCustomPermissions(),panel.getId(), permission.getAccessType(),PublishedStatus.PUBLISHED.value);
log.info("更新仪表板树");
updateTree(config, panel);
InstrumentPanelDraft draft = draftService.getByPanelId(panel.getId());
if (ObjectUtils.isNotEmpty(draft)) {
String beforeId =draft.getId();
BeanUtils.copyProperties(panel, draft);
draft.setId(beforeId);
draft.setPanelId(panel.getId());
draftService.updateById(draft);
} else {
InstrumentPanelDraft df = new InstrumentPanelDraft();
BeanUtils.copyProperties(panel, draft);
BeanUtils.copyProperties(panel, df);
df.setId(IdWorker.get32UUID());
df.setPanelId(panel.getId());
df.setPublished(PublishedStatus.PUBLISHED.value);
draftService.save(df);
}
panelService.updateById(panel);
return panel.getId();
}
......@@ -115,20 +119,16 @@ public class InstrumentPanelConfigServiceImpl extends ServiceImpl<InstrumentPane
checkAll(appId, config, permission);
InstrumentPanel panel = panelService.getById(config.getPanelId());
fillPanelProp(permission, panel);
fillPanelProp(permission, panel,PublishedStatus.WAIT_PUBLISHED.value);
//判断是否有发布版本
InstrumentPanelDraft draft = draftService.getByPanelId(panel.getId());
if (ObjectUtils.isNotEmpty(draft)) {
log.info("保存配置详情");
savePanelConfig(panel.getId(), config.getConfigDetails(), PublishedStatus.WAIT_PUBLISHED.value);
log.info("保存权限信息");
permissionService.savePanelPermission(permission.getCustomPermissions(),
panel.getId(),
permission.getAccessType(),
PublishedStatus.WAIT_PUBLISHED.value);
log.info("更新仪表盘树");
treeService.updatePanelTreeFullName(panel.getId(), panel.getName(), panel.getGroupId());
log.info("删除待发布配置详情");
delConfig(panel.getId(),PublishedStatus.WAIT_PUBLISHED.value);
log.info("删除仪表板权限信息");
permissionService.delPermissionByPanelId(config.getPanelId(), PublishedStatus.WAIT_PUBLISHED.value);
log.info("更新发布版本的groupId");
draft.setGroupId(permission.getGroupId());
draftService.updateById(draft);
......@@ -137,19 +137,18 @@ public class InstrumentPanelConfigServiceImpl extends ServiceImpl<InstrumentPane
//修改
log.info("删除仪表板配置详情");
delConfig(config.getPanelId(), null);
log.info("保存配置详情");
savePanelConfig(panel.getId(), config.getConfigDetails(), PublishedStatus.WAIT_PUBLISHED.value);
log.info("删除仪表板权限信息");
permissionService.delPermissionByPanelId(config.getPanelId(), null);
}
log.info("保存配置详情");
savePanelConfig(panel.getId(), config.getConfigDetails(), PublishedStatus.WAIT_PUBLISHED.value);
log.info("保存权限信息");
permissionService.savePanelPermission(permission.getCustomPermissions(),
panel.getId(),
permission.getAccessType(),
PublishedStatus.WAIT_PUBLISHED.value);
permissionService.savePanelPermission(permission.getCustomPermissions(),panel.getId(),permission.getAccessType(),PublishedStatus.WAIT_PUBLISHED.value);
log.info("更新仪表板树");
updateTree(config, panel);
}
panelService.updateById(panel);
return config.getPanelId();
}
......@@ -161,12 +160,15 @@ public class InstrumentPanelConfigServiceImpl extends ServiceImpl<InstrumentPane
if (StringUtils.isEmpty(permission.getPanelName())) {
throw new SysException("仪表板名字必填");
}
if (StringUtils.isEmpty(permission.getGroupId())) {
throw new SysException("仪表板分组必填");
}
log.info("校验仪表板名称是否重复");
panelService.checkName(appId, config.getPanelId(), permission.getPanelName());
}
@Override
public void delConfig(@NotNull String panelId, Integer publishedStatus) {
public void delConfig(@NotNull String panelId, String publishedStatus) {
List<InstrumentPanelConfig> configs = getConfigByPanelIdAndPublishStatus(panelId,publishedStatus);
if (CollectionUtils.isNotEmpty(configs)) {
configs.forEach(x -> {
......@@ -177,7 +179,7 @@ public class InstrumentPanelConfigServiceImpl extends ServiceImpl<InstrumentPane
}
@Override
public void savePanelConfig(String panelId, String configDetails, Integer publishStatus) {
public void savePanelConfig(String panelId, String configDetails, String publishStatus) {
InstrumentPanelConfig panelConfig = new InstrumentPanelConfig();
panelConfig.setId(IdWorker.get32UUID());
panelConfig.setPanelId(panelId);
......@@ -225,7 +227,7 @@ public class InstrumentPanelConfigServiceImpl extends ServiceImpl<InstrumentPane
@Override
@Transactional(readOnly = true)
public List<InstrumentPanelConfig> getConfigByPanelIdAndPublishStatus(String panelId, Integer publishStatus) {
public List<InstrumentPanelConfig> getConfigByPanelIdAndPublishStatus(String panelId, String publishStatus) {
LambdaQueryWrapper<InstrumentPanelConfig> where = new LambdaQueryWrapper<>();
where.eq(BaseEntity::getRecordStatus, SlmConstants.DATA_VALID);
where.eq(InstrumentPanelConfig::getPanelId, panelId);
......@@ -236,7 +238,7 @@ public class InstrumentPanelConfigServiceImpl extends ServiceImpl<InstrumentPane
}
@Override
public void offlineConfig(String panelId, Integer publishStatus) {
public void offlineConfig(String panelId, String publishStatus) {
List<InstrumentPanelConfig> configs = getConfigByPanelIdAndPublishStatus(panelId, publishStatus);
InstrumentPanelConfig waitConfig = configs.stream()
......@@ -268,12 +270,49 @@ public class InstrumentPanelConfigServiceImpl extends ServiceImpl<InstrumentPane
}
}
@Override
@Transactional
public Map<String, String> getAssemblyConfig(@NotNull String panelId) {
Map<String,String> maps = Maps.newHashMap();
LambdaQueryWrapper<InstrumentPanelConfig> where = new LambdaQueryWrapper<>();
where.eq(BaseEntity::getRecordStatus, SlmConstants.DATA_VALID);
where.eq(InstrumentPanelConfig::getPanelId, panelId);
List<InstrumentPanelConfig> configs = baseMapper.selectList(where);
if(CollectionUtils.isNotEmpty(configs)){
InstrumentPanelConfig waitConfig = configs.stream()
.filter(x -> PublishedStatus.WAIT_PUBLISHED.value.equals(x.getPublished()))
.findFirst()
.orElse(null);
if(ObjectUtils.isNotEmpty(waitConfig)){
try {
maps.put(PublishedStatus.WAIT_PUBLISHED.value,URLDecoder.decode(waitConfig.getConfigDetails(),StandardCharsets.UTF_8.name()));
}catch (Exception e){
e.printStackTrace();
}
}
InstrumentPanelConfig publishConfig = configs.stream()
.filter(x -> PublishedStatus.PUBLISHED.value.equals(x.getPublished()))
.findFirst()
.orElse(null);
if(ObjectUtils.isNotEmpty(publishConfig)){
try {
maps.put(PublishedStatus.PUBLISHED.value,URLDecoder.decode(publishConfig.getConfigDetails(),StandardCharsets.UTF_8.name()));
}catch (Exception e){
e.printStackTrace();
}
}
}
return maps;
}
private InstrumentPanelConfigVo getInstrumentPanelConfigVo(String instrumentPanelId, PublishedStatus published) {
LambdaQueryWrapper<InstrumentPanelConfig> where = new LambdaQueryWrapper<>();
where.eq(BaseEntity::getRecordStatus, SlmConstants.DATA_VALID);
where.eq(InstrumentPanelConfig::getPanelId, instrumentPanelId);
where.eq(InstrumentPanelConfig::getPublished, published.value);
InstrumentPanelConfig config = baseMapper.selectOne(where);
if(ObjectUtils.isNotEmpty(config)) {
InstrumentPanelConfigVo vo = new InstrumentPanelConfigVo();
BeanUtils.copyProperties(config, vo);
if (ObjectUtils.isNotEmpty(vo)) {
......@@ -294,15 +333,18 @@ public class InstrumentPanelConfigServiceImpl extends ServiceImpl<InstrumentPane
BeanUtils.copyProperties(panel, panelVo);
}
vo.setPanel(panelVo);
}
return vo;
}
}
return null;
}
private void fillPanelProp(InstrumentPanelPermissionDTO permission, InstrumentPanel panel) {
private void fillPanelProp(InstrumentPanelPermissionDTO permission, InstrumentPanel panel,String publishStatus) {
panel.setGroupId(permission.getGroupId());
panel.setName(permission.getPanelName());
panel.setAccessPermission(permission.getAccessType());
panel.setDescription(permission.getDescription());
panel.setPublished(publishStatus);
}
private void updateTree(InstrumentPanelConfigDTO config, InstrumentPanel panel) {
......
......@@ -62,11 +62,7 @@ public class InstrumentPanelDraftServiceImpl extends ServiceImpl<InstrumentPanel
}
@Override
public List<InstrumentPanelDraft> selectDraftList(String appId,
Set<String> panelIds,
String officeIds,
String userId,
String roleId) {
public List<InstrumentPanelDraft> selectDraftList(String appId, Set<String> panelIds, String officeIds, String userId, String roleId) {
return baseMapper.selectDraftList(appId, panelIds, officeIds, userId, roleId);
}
......
......@@ -117,6 +117,9 @@ public class InstrumentPanelGroupServiceImpl extends ServiceImpl<InstrumentPanel
if(StringUtils.isEmpty(group.getName())){
throw new SysException("仪表板分组名称必填");
}
if(StringUtils.isEmpty(group.getParentId())){
throw new SysException("父级分组必填");
}
log.info("检查分组名字是否重复");
checkedRepeatName.call(group,appId);
InstrumentPanelGroup entity = new InstrumentPanelGroup();
......
......@@ -70,7 +70,8 @@ public class InstrumentPanelPermissionImpl
InstrumentPanel panel = panelService.getById(permissions.getPanelId());
panel.setName(permissions.getPanelName());
panel.setGroupId(permissions.getGroupId());
permissions.setAccessType(permissions.getAccessType());
panel.setAccessPermission(permissions.getAccessType());
panel.setDescription(permissions.getDescription());
log.info("删除原本的权限");
delPermissionByPanelId(permissions.getPanelId(), PublishedStatus.WAIT_PUBLISHED.value);
......@@ -97,10 +98,14 @@ public class InstrumentPanelPermissionImpl
throw new SysException("访问权限类型必填");
}
List<InstrumentPanel> panels = panelService.getByIds(Sets.newHashSet(otherInstrumentPanelIds));
if(CollectionUtils.isEmpty(panels)){
throw new SysException("查找不到对应的仪表板,请联系管理员");
}
panels.forEach(panel->{
panel.setAccessPermission(permissions.getAccessType());
panel.setDescription(permissions.getDescription());
log.info("删除原本的权限");
delPermissionByPanelId(permissions.getPanelId(), PublishedStatus.WAIT_PUBLISHED.value);
delPermissionByPanelId(panel.getId(), PublishedStatus.WAIT_PUBLISHED.value);
log.info("插入现有的权限");
savePanelPermission(permissions.getCustomPermissions(), panel.getId(), panel.getAccessPermission(), PublishedStatus.WAIT_PUBLISHED.value);
......@@ -116,6 +121,7 @@ public class InstrumentPanelPermissionImpl
InstrumentPanelPermissionVo vo = new InstrumentPanelPermissionVo();
InstrumentPanel panel = panelService.getById(instrumentPanelId);
vo.setAccessType(panel.getAccessPermission());
vo.setDescription(panel.getDescription());
List<CustomPermissionVo> vos = getPublishPermissionByPanelId(instrumentPanelId, PublishedStatus.WAIT_PUBLISHED.value);
if(CollectionUtils.isEmpty(vos)){
vos = getPublishPermissionByPanelId(instrumentPanelId, PublishedStatus.PUBLISHED.value);
......@@ -125,7 +131,7 @@ public class InstrumentPanelPermissionImpl
}
@Override
public void delPermissionByPanelId(@NonNull String panelId, Integer publishStatus) {
public void delPermissionByPanelId(@NonNull String panelId, String publishStatus) {
List<InstrumentPanelPermission> permissions =getPermissionByPanelIdAndPublishStatus(panelId,publishStatus);
if (CollectionUtils.isNotEmpty(permissions)) {
permissions.forEach(x -> {
......@@ -138,7 +144,7 @@ public class InstrumentPanelPermissionImpl
@Override
@Transactional(readOnly = true)
public List<CustomPermissionVo> getPublishPermissionByPanelId(@NonNull String panelId,
@NonNull Integer publishStatus) {
@NonNull String publishStatus) {
List<InstrumentPanelPermission> permissions = getPermissionByPanelIdAndPublishStatus(panelId,publishStatus);
return CollectionUtils.isNotEmpty(permissions) ? SlmConstants.gson.fromJson(SlmConstants.gson.toJson(permissions), new TypeToken<List<CustomPermissionVo>>() {}.getType()) : null;
}
......@@ -147,7 +153,7 @@ public class InstrumentPanelPermissionImpl
public void savePanelPermission(List<CustomPermissionDTO> customPermissions,
String panelId,
String accessType,
Integer publishStatus) {
String publishStatus) {
if (CollectionUtils.isNotEmpty(customPermissions)) {
if (AccessType.CUSTOM.value.equals(accessType)) {
if (CollectionUtils.isNotEmpty(customPermissions)) {
......@@ -195,7 +201,7 @@ public class InstrumentPanelPermissionImpl
}
@Override
public List<InstrumentPanelPermission> getPermissionByPanelIdAndPublishStatus(String panelId, Integer publishStatus) {
public List<InstrumentPanelPermission> getPermissionByPanelIdAndPublishStatus(String panelId, String publishStatus) {
LambdaQueryWrapper<InstrumentPanelPermission> where = new LambdaQueryWrapper<>();
where.eq(InstrumentPanelPermission::getPanelId, panelId);
where.eq(InstrumentPanelPermission::getRecordStatus, SlmConstants.DATA_VALID);
......
......@@ -61,7 +61,13 @@ public class InstrumentPanelServiceImpl extends ServiceImpl<InstrumentPanelMappe
public IPage<InstrumentPanelVo> selectInstrumentPanelList(String appId, QueryInstrumentPanelDTO query) {
IPage<InstrumentPanelVo> page = new Page<>(query.getCurrent(), query.getSize());
QueryWrapper<InstrumentPanel> where = new QueryWrapper<>();
if(StringUtils.isEmpty(appId)){
throw new SysException("appId必须传入");
}
where.eq("p.app_id", appId);
if(StringUtils.isEmpty(query.getGroupId())){
throw new SysException("必须选择需要查询的仪表板分组");
}
where.eq("p.group_id", query.getGroupId());
where.eq("p.record_status", SlmConstants.DATA_VALID);
if (StringUtils.isNotEmpty(query.getName())) {
......@@ -94,7 +100,7 @@ public class InstrumentPanelServiceImpl extends ServiceImpl<InstrumentPanelMappe
@Override
@Transactional(rollbackFor = Exception.class)
public void batchPublish(List<String> ids) {
public List<String> batchPublish(List<String> ids) {
if (CollectionUtils.isEmpty(ids)) {
throw new SysException("请选择你要操作的数据");
}
......@@ -111,7 +117,7 @@ public class InstrumentPanelServiceImpl extends ServiceImpl<InstrumentPanelMappe
log.info("复制一份草稿");
draftService.saveDrafts(panels);
}
return ids;
}
@Override
......@@ -201,7 +207,7 @@ public class InstrumentPanelServiceImpl extends ServiceImpl<InstrumentPanelMappe
wrapper.eq(InstrumentPanel::getAppId, appId);
wrapper.eq(InstrumentPanel::getRecordStatus, SlmConstants.DATA_VALID);
if (StringUtils.isNotEmpty(panelId)) {
wrapper.eq(InstrumentPanel::getId, panelId);
wrapper.ne(InstrumentPanel::getId, panelId);
}
if (baseMapper.selectCount(wrapper) > 0) {
throw new SysException("仪表板名字:" + panelName + "已存在!");
......
......@@ -2,10 +2,12 @@ package com.syc.slm.slmbi.service.impl;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
import com.baomidou.mybatisplus.core.toolkit.IdWorker;
import com.baomidou.mybatisplus.core.toolkit.ObjectUtils;
import com.baomidou.mybatisplus.core.toolkit.StringUtils;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.google.common.collect.Lists;
import com.google.common.collect.Maps;
import com.google.common.collect.Sets;
import com.google.gson.reflect.TypeToken;
import com.syc.slm.common.core.constant.SlmConstants;
......@@ -13,15 +15,15 @@ import com.syc.slm.slmbi.dao.InstrumentPanelTreeMapper;
import com.syc.slm.slmbi.dto.InstrumentPanelAssemblyDTO;
import com.syc.slm.slmbi.entity.*;
import com.syc.slm.slmbi.enums.NodeType;
import com.syc.slm.slmbi.enums.PublishedStatus;
import com.syc.slm.slmbi.exception.SysException;
import com.syc.slm.slmbi.service.InstrumentPanelDraftService;
import com.syc.slm.slmbi.service.InstrumentPanelGroupService;
import com.syc.slm.slmbi.service.InstrumentPanelService;
import com.syc.slm.slmbi.service.InstrumentPanelTreeService;
import com.syc.slm.slmbi.service.*;
import com.syc.slm.slmbi.vo.CustomPermissionVo;
import com.syc.slm.slmbi.vo.InstrumentPanelConfigVo;
import com.syc.slm.slmbi.vo.InstrumentPanelGroupVo;
import com.syc.slm.slmbi.vo.PanelTreeNodeVo;
import lombok.NonNull;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.io.filefilter.FalseFileFilter;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
......@@ -37,6 +39,7 @@ import java.util.stream.Collectors;
* @date 2021-04-01 10:52:44
*/
@Service
@Slf4j
public class InstrumentPanelTreeServiceImpl extends ServiceImpl<InstrumentPanelTreeMapper, InstrumentPanelTree>
implements InstrumentPanelTreeService {
......@@ -45,6 +48,8 @@ public class InstrumentPanelTreeServiceImpl extends ServiceImpl<InstrumentPanelT
@Autowired
private InstrumentPanelGroupService groupService;
@Autowired
private InstrumentPanelConfigService configService;
@Autowired
private InstrumentPanelService panelService;
......@@ -87,19 +92,20 @@ public class InstrumentPanelTreeServiceImpl extends ServiceImpl<InstrumentPanelT
@Override
public void savePanelAssemblyTree(InstrumentPanelTree tree,List<InstrumentPanelAssemblyDTO> assembly,String panelId) {
if (CollectionUtils.isNotEmpty(assembly)) {
for (int i = 0; i < assembly.size(); i++) {
if(StringUtils.isBlank(assembly.get(i).getName()) || StringUtils.isBlank(assembly.get(i).getKey())){
throw new SysException("主键名称或者key不能为空,请联系管理员");
}
assembly.forEach(x->{
if(StringUtils.isBlank(x.getName()) || StringUtils.isBlank(x.getKey())){
log.info("不要传入空得组件树");
}else {
InstrumentPanelTree t = new InstrumentPanelTree();
t.setId(tree.getId() + "_" + i);
t.setId(IdWorker.get32UUID());
t.setNodeType(NodeType.ASSEMBLY.value);
t.setFullId(tree.getFullId() + "." + t.getId());
t.setFullName(tree.getFullName() + "." + assembly.get(i).getName());
t.setAssemblyKey(assembly.get(i).getKey());
t.setName(assembly.get(i).getName());
t.setFullName(tree.getFullName() + "." + x.getName());
t.setAssemblyKey(x.getKey());
t.setName(x.getName());
baseMapper.insert(t);
}
});
}
}
......@@ -318,16 +324,24 @@ public class InstrumentPanelTreeServiceImpl extends ServiceImpl<InstrumentPanelT
InstrumentPanelTree panelTree = baseMapper.selectById(panelId);
String beforeFullName = panelTree.getFullName();
String beforeFullId = panelTree.getFullId();
log.info("更新自身的树状结构");
panelTree.setFullName(group.getFullName()+"."+panelName);
panelTree.setFullId(group.getFullId()+"."+panelId);
panelTree.setName(panelName);
baseMapper.updateById(panelTree);
if(ObjectUtils.isNotEmpty(group)){
log.info("更新组件的树状结构");
LambdaQueryWrapper<InstrumentPanelTree> where = new LambdaQueryWrapper<>();
where.eq(BaseEntity::getRecordStatus, SlmConstants.DATA_VALID);
where.likeRight(InstrumentPanelTree::getFullId, group.getFullId() + ".");
where.likeRight(InstrumentPanelTree::getFullId, beforeFullId+".");
List<InstrumentPanelTree> trees = baseMapper.selectList(where);
if(CollectionUtils.isNotEmpty(trees)){
trees.forEach(x->{
x.setFullId(x.getFullId().replace(beforeFullId, group.getFullId()));
String name = x.getFullName().substring(x.getFullName().lastIndexOf(beforeFullName));
x.setFullName(group.getFullName()+"." + name);
x.setFullId(x.getFullId().replace(beforeFullId, panelTree.getFullId()));
String name = x.getFullName().substring(beforeFullName.length()+1);
x.setFullName(panelTree.getFullName()+"." + name);
x.setName(name);
baseMapper.updateById(x);
});
......@@ -347,6 +361,11 @@ public class InstrumentPanelTreeServiceImpl extends ServiceImpl<InstrumentPanelT
return getCopyAndCiteTrees(appId, name, true);
}
@Override
public Map<String, String> assembly(String appId, String panelId) {
return configService.getAssemblyConfig(panelId);
}
private List<PanelTreeNodeVo> getCopyAndCiteTrees(String appId, String name,boolean showAssembly) {
LambdaQueryWrapper<InstrumentPanelTree> where = new LambdaQueryWrapper<>();
where.eq(BaseEntity::getAppId, appId);
......
......@@ -22,6 +22,8 @@ public class InstrumentPanelPermissionVo {
@ApiModelProperty(value = "访问权限类型", required = true)
private String accessType;
@ApiModelProperty(value = "描述", required = true)
private String description;
@ApiModelProperty(value = "自定义权限配置,当访问类型为CUSTOM时必填")
private List<CustomPermissionVo> customPermissions;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment