Commit 1023f6af authored by linruibiao's avatar linruibiao

接口编写

parent 95fd45c3
......@@ -35,10 +35,10 @@ public class SysMetaObjectHandler implements MetaObjectHandler {
public void insertFill(MetaObject metaObject) {
fillValue(metaObject,
APP_ID,
() -> (metaObject.getValue(APP_ID) == null ? IdWorker.get32UUID() : metaObject.getValue(APP_ID)));
() -> (metaObject.getValue(APP_ID) == null ? "68d61d7f990e11eb847e88d7f63cc98f" : metaObject.getValue(APP_ID)));
fillValue(metaObject,
CREATOR,
() -> (metaObject.getValue(CREATOR) == null ? IdWorker.get32UUID() : metaObject.getValue(CREATOR)));
() -> (metaObject.getValue(CREATOR) == null ? "68d61d7f990e11eb847e88d7f63cc98f" : metaObject.getValue(CREATOR)));
fillValue(metaObject,
CREATOR_NAME,
() -> (metaObject.getValue(CREATOR_NAME) == null ? "小明" : metaObject.getValue(CREATOR_NAME)));
......@@ -52,7 +52,7 @@ public class SysMetaObjectHandler implements MetaObjectHandler {
@Override
public void updateFill(MetaObject metaObject) {
setFieldValByName(UPDATER, IdWorker.get32UUID(), metaObject);
setFieldValByName(UPDATER, "68d61d7f990e11eb847e88d7f63cc98f", metaObject);
setFieldValByName(UPDATER_NAME, "小明",metaObject);
setFieldValByName(UPDATE_TIME, new Date(), metaObject);
}
......
......@@ -14,6 +14,7 @@ import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import java.util.Arrays;
import java.util.List;
/**
......@@ -57,9 +58,9 @@ public class InstrumentPanelController extends BaseRestController {
@ApiImplicitParams({@ApiImplicitParam(name = "ids",
value = "仪表板id集合",
required = true,
dataTypeClass = String.class),
dataTypeClass = Arrays.class),
@ApiImplicitParam(name = "appId", value = "租户id", required = true, dataTypeClass = String.class)})
public R<Object> batchPublish(@PathVariable String appId, @RequestBody List<String> ids) {
public R<Object> batchPublish(@PathVariable String appId, @RequestParam List<String> ids) {
return call(() -> instrumentPanelService.batchPublish(ids));
}
......
......@@ -34,7 +34,7 @@ public class InstrumentPanelGroupController extends BaseRestController{
@ApiOperation("仪表板列表查询,仪表板分组增删改页面的分组树")
@ApiImplicitParams({
@ApiImplicitParam(name = "appId", value = "租户id", required = true,dataTypeClass = String.class),
@ApiImplicitParam(name = "name", value = "分组名称", required = true,dataTypeClass = String.class)
@ApiImplicitParam(name = "name", value = "分组名称",dataTypeClass = String.class)
})
public R<List<InstrumentPanelGroupVo>> selectGroupList(@PathVariable String appId, @RequestParam(required = false,value = "name") String name) {
return call(()->instrumentPanelGroupService.selectGroupList(appId,name));
......@@ -44,14 +44,14 @@ public class InstrumentPanelGroupController extends BaseRestController{
@ApiOperation("保存仪表板分组")
@ApiImplicitParam(name = "appId", value = "租户id", required = true,dataTypeClass = String.class)
public R<String> saveGroup(@PathVariable String appId, @RequestBody CreateInstrumentPanelGroupDTO group) {
return call(()->instrumentPanelGroupService.saveGroup(group));
return call(()->instrumentPanelGroupService.saveGroup(group,appId));
}
@PutMapping
@ApiOperation("更新仪表板分组")
@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));
return call(()->instrumentPanelGroupService.updateGroup(group,appId));
}
@DeleteMapping("/{groupId}")
......
......@@ -11,6 +11,7 @@ import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import java.util.Arrays;
import java.util.List;
/**
......@@ -23,43 +24,52 @@ import java.util.List;
@Api(value = "仪表板权限控制", tags = "仪表板权限控制")
@RestController
@RequestMapping("/{appId}/panel-permissions")
public class InstrumentPanelPermissionController {
public class InstrumentPanelPermissionController extends BaseRestController {
@Autowired
private InstrumentPanelPermissionService instrumentPanelPermissionService;
@PostMapping
@ApiOperation("保存仪表板权限(列表的属性保存)")
@ApiImplicitParam(name = "appId", value = "租户id", required = true,dataTypeClass = String.class)
@ApiImplicitParam(name = "appId", value = "租户id", required = true, dataTypeClass = String.class)
public R<String> savePermission(@PathVariable String appId, @RequestBody InstrumentPanelPermissionDTO permission) {
return R.ok(instrumentPanelPermissionService.savePermission(permission));
return call(() -> instrumentPanelPermissionService.savePermission(permission));
}
@PostMapping("/{panelId}/to-copy")
@PutMapping("/{panelId}/to-copy")
@ApiOperation("从其他仪表板复制配置")
@ApiImplicitParams({@ApiImplicitParam(name = "appId", value = "租户id", required = true,dataTypeClass = String.class),
@ApiImplicitParam(name = "panelId", value = "其他仪表板id", required = true,dataTypeClass = String.class)})
public R<List<InstrumentPanelPermissionVo>> saveCopyOtherPermission(@PathVariable String appId,
@ApiImplicitParams({@ApiImplicitParam(name = "appId",
value = "租户id",
required = true,
dataTypeClass = String.class),
@ApiImplicitParam(name = "panelId", value = "其他仪表板id", required = true, dataTypeClass = String.class)})
public R<InstrumentPanelPermissionVo> saveCopyOtherPermission(@PathVariable String appId,
@PathVariable String panelId) {
return R.ok(instrumentPanelPermissionService.saveCopyOtherPermission(panelId));
return call(() -> (instrumentPanelPermissionService.saveCopyOtherPermission(panelId)));
}
@PostMapping("/{panelId}/copy-to")
@PostMapping("/copy-to")
@ApiOperation("将仪表板权限复制给其他仪表板")
@ApiImplicitParams({@ApiImplicitParam(name = "appId", value = "租户id", required = true,dataTypeClass = String.class),
@ApiImplicitParam(name = "panelId", value = "其他仪表板id", required = true,dataTypeClass = String.class)})
public R<String> saveCopyToOtherPermission(@PathVariable String appId,
@ApiImplicitParams({@ApiImplicitParam(name = "appId",
value = "租户id",
required = true,
dataTypeClass = String.class),
@ApiImplicitParam(name = "panelId", value = "其他仪表板id", required = true, dataTypeClass = Arrays.class)})
public R<Object> saveCopyToOtherPermission(@PathVariable String appId,
@RequestBody InstrumentPanelPermissionDTO permission,
@PathVariable String panelId) {
return R.ok(instrumentPanelPermissionService.saveCopyToOtherPermission(permission, panelId));
@RequestParam List<String> panelIds) {
return call(() -> instrumentPanelPermissionService.saveCopyToOtherPermission(permission, panelIds));
}
@GetMapping("/{panelId}")
@ApiOperation("根据仪表板id获取仪表板权限")
@ApiImplicitParams({@ApiImplicitParam(name = "appId", value = "租户id", required = true,dataTypeClass = String.class),
@ApiImplicitParam(name = "panelId", value = "其他仪表板id", required = true,dataTypeClass = String.class)})
public R<List<InstrumentPanelPermissionVo>> selectPermissionByPanelId(@PathVariable String appId,
@ApiImplicitParams({@ApiImplicitParam(name = "appId",
value = "租户id",
required = true,
dataTypeClass = String.class),
@ApiImplicitParam(name = "panelId", value = "其他仪表板id", required = true, dataTypeClass = String.class)})
public R<InstrumentPanelPermissionVo> selectPermissionByPanelId(@PathVariable String appId,
@PathVariable String panelId) {
return R.ok(instrumentPanelPermissionService.selectPermissionByPanelId(panelId));
return call(() -> (instrumentPanelPermissionService.selectPermissionByPanelId(panelId)));
}
}
package com.syc.slm.slmbi.controller;
import com.syc.slm.common.core.util.R;
import com.syc.slm.slmbi.service.InstrumentPanelGroupService;
import com.syc.slm.slmbi.vo.InstrumentPanelGroupVo;
import com.syc.slm.slmbi.service.InstrumentPanelConfigService;
import com.syc.slm.slmbi.service.InstrumentPanelTreeService;
import com.syc.slm.slmbi.vo.InstrumentPanelConfigVo;
import com.syc.slm.slmbi.vo.PanelTreeNodeVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
......@@ -20,36 +21,80 @@ import java.util.List;
@RestController
@RequestMapping("/{appId}/panel-tree")
@Api(value = "仪表板树接口", tags = "仪表板树接口")
public class InstrumentPanelTreeController {
public class InstrumentPanelTreeController extends BaseRestController {
@Autowired
private InstrumentPanelTreeService treeService;
@Autowired
private InstrumentPanelGroupService instrumentPanelGroupService;
private InstrumentPanelConfigService configService;
@GetMapping
@ApiOperation("第一次进入页面,或者点击查询,获取全部分组下的仪表板数据,以及分组数据")
@ApiImplicitParams({@ApiImplicitParam(name = "appId", value = "租户id", required = true,dataTypeClass = String.class),
@ApiImplicitParam(name = "name", value = "分组名称或者仪表板名称",dataTypeClass = String.class)})
@ApiOperation("显示已发布仪表板树==》(刚进入页面)")
@ApiImplicitParam(name = "appId", value = "租户id", required = true, dataTypeClass = String.class)
public R<List<PanelTreeNodeVo>> loadTrees(@PathVariable String appId) {
return call(() -> (treeService.loadTrees(appId)));
}
@GetMapping("/search")
@ApiOperation("显示已发布仪表板树==》(点击查询)")
@ApiImplicitParams({@ApiImplicitParam(name = "appId",
value = "租户id",
required = true,
dataTypeClass = String.class),
@ApiImplicitParam(name = "name", value = "分组名称或者仪表板名称", dataTypeClass = String.class)})
public R<List<PanelTreeNodeVo>> loadTrees(@PathVariable String appId,
@RequestParam(value = "name", required = false) String name) {
return R.ok(instrumentPanelGroupService.loadTrees(name));
return call(() -> (treeService.loadTrees(appId, name)));
}
@GetMapping("/children")
@ApiOperation("点击节点获取,该分组下的仪表板信息,以及分组数据")
@ApiImplicitParams({@ApiImplicitParam(name = "appId", value = "租户id", required = true,dataTypeClass = String.class),
@ApiImplicitParam(name = "groupId", value = "分组id", required = true,dataTypeClass = String.class),
@ApiImplicitParam(name = "name", value = "分组名称或者仪表板名称",dataTypeClass = String.class)})
@ApiOperation("点击节点,显示已发布仪表板树")
@ApiImplicitParams({@ApiImplicitParam(name = "appId",
value = "租户id",
required = true,
dataTypeClass = String.class),
@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("groupId") String groupId,
@RequestParam("nodeId") String groupId,
@RequestParam(value = "name", required = false) String name) {
return R.ok(instrumentPanelGroupService.children(groupId, name));
return call(() -> (treeService.children(groupId, name)));
}
// FIXME 使用场景?
@GetMapping("/selectInstrumentPanelGroups")
//@ApiOperation("获取所有的仪表板分组以及分组下的仪表板以及仪表板下的组件")
public R<List<InstrumentPanelGroupVo>> selectInstrumentPanelGroups() {
return R.ok();
@GetMapping("/children-panel")
@ApiOperation("点击节点,显示已发布仪表板配置")
@ApiImplicitParams({@ApiImplicitParam(name = "appId",
value = "租户id",
required = true,
dataTypeClass = String.class),
@ApiImplicitParam(name = "panelId", value = "仪表板id", required = true, dataTypeClass = String.class)})
public R<InstrumentPanelConfigVo> childrenPanel(@PathVariable String appId, @RequestParam("nodeId") String nodeId) {
return call(() -> (configService.getPublishConfigByPanelId(nodeId)));
}
// TODO 树搜索
@GetMapping("/copy")
@ApiOperation("复制仪表板配置树")
@ApiImplicitParams({@ApiImplicitParam(name = "appId",
value = "租户id",
required = true,
dataTypeClass = String.class),
@ApiImplicitParam(name = "appId", value = "租户id", required = true, dataTypeClass = String.class),
@ApiImplicitParam(name = "name", value = "分组名称或者仪表板名称", dataTypeClass = String.class)})
public R<List<PanelTreeNodeVo>> copyTreeList(@PathVariable String appId,@RequestParam(value = "name", required = false) String name) {
return call(() -> (treeService.copyTreeList(appId,name)));
}
@GetMapping("/cite")
@ApiOperation("复用仪表板树")
@ApiImplicitParams({@ApiImplicitParam(name = "appId",
value = "租户id",
required = true,
dataTypeClass = String.class),
@ApiImplicitParam(name = "appId", value = "租户id", required = true, dataTypeClass = String.class),
@ApiImplicitParam(name = "name", value = "分组名称,仪表板名称,组件名称", dataTypeClass = String.class)})
public R<List<PanelTreeNodeVo>> cite(@PathVariable String appId,@RequestParam(value = "name", required = false) String name) {
return call(() -> (treeService.citeTreeList(appId,name)));
}
}
package com.syc.slm.slmbi.dao;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.syc.slm.slmbi.entity.InstrumentPanelDraft;
import org.apache.ibatis.annotations.Param;
import org.springframework.stereotype.Component;
import java.util.List;
import java.util.Set;
/**
* 仪表板草稿
*
......@@ -12,4 +16,6 @@ import org.springframework.stereotype.Component;
@Component
public interface InstrumentPanelDraftMapper extends BaseMapper<InstrumentPanelDraft> {
List<InstrumentPanelDraft> selectDraftList(@Param("appId") String appId,@Param("panelIds") Set<String> panelIds, @Param("officeIds") String officeIds, @Param(
"userId") String userId, @Param("roleId") String roleId);
}
......@@ -4,6 +4,7 @@ import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.syc.slm.slmbi.entity.InstrumentPanelGroup;
import com.syc.slm.slmbi.vo.InstrumentPanelGroupVo;
import com.syc.slm.slmbi.vo.PanelTreeNodeVo;
import org.apache.ibatis.annotations.Param;
import org.springframework.stereotype.Component;
......@@ -32,4 +33,6 @@ public interface InstrumentPanelGroupMapper extends BaseMapper<InstrumentPanelGr
* @return
*/
List<InstrumentPanelGroupVo> selectGroupList(@Param("ew") LambdaQueryWrapper<InstrumentPanelGroup> where);
List<PanelTreeNodeVo> selectGroupByIds(@Param("finalPanelIds") Set<String> finalPanelIds, @Param("name") String name);
}
......@@ -6,9 +6,11 @@ import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.syc.slm.slmbi.entity.InstrumentPanel;
import com.syc.slm.slmbi.vo.InstrumentPanelVo;
import com.syc.slm.slmbi.vo.PanelTreeNodeVo;
import org.apache.ibatis.annotations.Param;
import org.springframework.stereotype.Component;
import java.util.List;
import java.util.Set;
/**
......@@ -25,4 +27,5 @@ public interface InstrumentPanelMapper extends BaseMapper<InstrumentPanel> {
IPage<InstrumentPanelVo> selectInstrumentPanelList(@Param("page") IPage<InstrumentPanelVo> page,
@Param("ew") Wrapper<InstrumentPanel> wrapper);
List<PanelTreeNodeVo> selectPanelByIds(@Param("finalPanelIds") Set<String> finalPanelIds, @Param("name") String name);
}
......@@ -2,9 +2,11 @@ package com.syc.slm.slmbi.dao;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.syc.slm.slmbi.entity.InstrumentPanelTree;
import com.syc.slm.slmbi.vo.PanelTreeNodeVo;
import org.apache.ibatis.annotations.Param;
import org.springframework.stereotype.Component;
import java.util.List;
import java.util.Set;
/**
......
......@@ -19,8 +19,8 @@ import java.util.List;
@ApiModel(value = "仪表板权限DTO", description = "仪表板权限DTO")
@EqualsAndHashCode(callSuper = false)
public class InstrumentPanelPermissionDTO {
@ApiModelProperty(value = "主键id")
private String id;
@ApiModelProperty(value = "仪表板主键id")
private String panelId;
@ApiModelProperty(value = "仪表板名称", required = true)
private String panelName;
......
......@@ -13,8 +13,8 @@ import lombok.Data;
public class QueryPageDTO {
@ApiModelProperty("页码")
private Integer pageNum = 1;
private Integer current = 1;
@ApiModelProperty("每页大小")
private Integer pageSize = 10;
private Integer size = 10;
}
......@@ -40,4 +40,7 @@ public class InstrumentPanelDraft extends BaseEntity<InstrumentPanelDraft> {
@ApiModelProperty(value = "状态(发布,下线)")
private String published;
@ApiModelProperty(value = "仪表板id")
private String panelId;
}
package com.syc.slm.slmbi.entity;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableName;
import com.baomidou.mybatisplus.extension.activerecord.Model;
import io.swagger.annotations.ApiModel;
......@@ -24,6 +25,9 @@ public class InstrumentPanelTree extends BaseEntity<InstrumentPanelTree> {
*/
@ApiModelProperty(value = "节点全路径id")
private String fullId;
@ApiModelProperty(value = "节点名字")
private String name;
/**
* 节点全路径
*/
......@@ -37,8 +41,11 @@ public class InstrumentPanelTree extends BaseEntity<InstrumentPanelTree> {
@ApiModelProperty(value = "组件key")
private String assemblyKey;
/* @ApiModelProperty(value = "业务id")
private String bizId;*/
@ApiModelProperty(value = "父级id")
@TableField(exist = false)
private String parentId;
}
package com.syc.slm.slmbi.function;
import java.io.Serializable;
/**
* Created by Yeshirow on 2018-01-16.
*/
public interface Action1<T> extends Serializable {
void call(T t);
@SafeVarargs
static <T1>Action1<T1>[] of(Action1<T1>... funcs){
return funcs;
}
}
package com.syc.slm.slmbi.function;
import java.io.Serializable;
/**
* Created by Yeshirow on 2018-01-16.
*/
public interface Action2<T1,T2> extends Serializable {
void call(T1 t1, T2 t2);
@SafeVarargs
static <T1,T2>Action2<T1,T2>[] of(Action2<T1, T2>... funcs){
return funcs;
}
}
......@@ -31,8 +31,10 @@ public interface InstrumentPanelConfigService extends IService<InstrumentPanelCo
* @return
*/
InstrumentPanelConfigVo getConfigByPanelId(@NotNull String instrumentPanelId);
/**
* 保存发布仪表板配置
* @param appId
* @param config
* @return
*/
......@@ -49,6 +51,7 @@ public interface InstrumentPanelConfigService extends IService<InstrumentPanelCo
/**
* 根据仪表板id删除仪表板配置
* @param panelId
* @param publishedStatus
*/
void delConfig(@NotNull String panelId,Integer publishedStatus);
......@@ -65,4 +68,19 @@ public interface InstrumentPanelConfigService extends IService<InstrumentPanelCo
* @param ids
*/
void publishConfigByPanelIds(List<String> ids);
/**
* 根据仪表板id以及状态获取仪表板配置
* @param panelId
* @param publishStatus
* @return
*/
List<InstrumentPanelConfig> getConfigByPanelIdAndPublishStatus(String panelId,Integer publishStatus);
/**
* 下线仪表盘配置
* @param panelId
* @param publishStatus
*/
void offlineConfig(String panelId, Integer publishStatus);
}
......@@ -5,6 +5,7 @@ import com.syc.slm.slmbi.entity.InstrumentPanel;
import com.syc.slm.slmbi.entity.InstrumentPanelDraft;
import java.util.List;
import java.util.Set;
/**
* 仪表板草稿
......@@ -19,4 +20,29 @@ public interface InstrumentPanelDraftService extends IService<InstrumentPanelDra
* @param panels
*/
void saveDrafts(List<InstrumentPanel> panels);
/**
* 根据仪表板id获取 仪表板草稿
* @param panelIds
* @return
*/
List<InstrumentPanelDraft> getByIds(Set<String> panelIds);
/**
* 获取仪表板信息
* @param appId
* @param panelIds
* @param officeIds
* @param userId
* @param roleId
* @return
*/
List<InstrumentPanelDraft> selectDraftList(String appId,Set<String> panelIds, String officeIds, String userId, String roleId);
/**
* 根据仪表板id获取 仪表板草稿
* @param panelId
* @return
*/
InstrumentPanelDraft getByPanelId(String panelId);
}
......@@ -8,6 +8,7 @@ import com.syc.slm.slmbi.vo.PanelTreeNodeVo;
import lombok.NonNull;
import java.util.List;
import java.util.Set;
/**
* slm-bi
......@@ -20,12 +21,15 @@ public interface InstrumentPanelGroupService extends IService<InstrumentPanelGro
/**
* 查询仪表板分组
* @param appId
* @param name
* @return
*/
List<InstrumentPanelGroupVo> selectGroupList(String appId,String name);
List<InstrumentPanelGroupVo> selectGroupList(String appId, String name);
/**
* 删除仪表板分组
*
* @param groupId
* @return
*/
......@@ -34,29 +38,24 @@ public interface InstrumentPanelGroupService extends IService<InstrumentPanelGro
/**
* 修改仪表板分组
* @param group
* @param appId
* @return
*/
String updateGroup(@NonNull InstrumentPanelGroupDTO group);
String updateGroup(@NonNull InstrumentPanelGroupDTO group,String appId);
/**
* 保存仪表板分组
* @param group
* @param appId
* @return
*/
String saveGroup(@NonNull InstrumentPanelGroupDTO group);
String saveGroup(@NonNull InstrumentPanelGroupDTO group,String appId);
/**
* 加载仪表板树
* @param name
* @return
*/
List<PanelTreeNodeVo> loadTrees(String name);
/**
* 查询下一节点分组
* @param groupId
* 根据分组id集合 已经名称批量查询仪表板分组
* @param finalPanelIds
* @param name
* @return
*/
List<PanelTreeNodeVo> children(String groupId, String name);
List<PanelTreeNodeVo> selectGroupByIds(Set<String> finalPanelIds,String name);
}
......@@ -31,16 +31,16 @@ public interface InstrumentPanelPermissionService extends IService<InstrumentPan
* @param instrumentPanelId
* @return
*/
List<InstrumentPanelPermissionVo> saveCopyOtherPermission(@NonNull String instrumentPanelId);
InstrumentPanelPermissionVo saveCopyOtherPermission(@NonNull String instrumentPanelId);
/**
* 将仪表板权限复制给其他仪表板
*
* @param permissions
* @param otherInstrumentPanelId
* @param otherInstrumentPanelIds
* @return
*/
String saveCopyToOtherPermission(InstrumentPanelPermissionDTO permissions, String otherInstrumentPanelId);
void saveCopyToOtherPermission(InstrumentPanelPermissionDTO permissions, List<String> otherInstrumentPanelIds);
/**
* 根据仪表板id获取仪表板权限
......@@ -48,7 +48,7 @@ public interface InstrumentPanelPermissionService extends IService<InstrumentPan
* @param instrumentPanelId
* @return
*/
List<InstrumentPanelPermissionVo> selectPermissionByPanelId(@NonNull String instrumentPanelId);
InstrumentPanelPermissionVo selectPermissionByPanelId(@NonNull String instrumentPanelId);
/**
* 根据仪表板id删除仪表板权限
......@@ -77,4 +77,18 @@ public interface InstrumentPanelPermissionService extends IService<InstrumentPan
* @param ids
*/
void publishPermissionByPanelIds(List<String> ids);
/**
* 根据仪表板id 以及 状态获取仪表板对应权限
* @param panelId
* @param publishStatus
* @return
*/
List<InstrumentPanelPermission> getPermissionByPanelIdAndPublishStatus(String panelId, Integer publishStatus);
/**
* 下线仪表板对应权限
* @param panelId
*/
void offlinePermission(String panelId);
}
......@@ -7,6 +7,7 @@ import com.syc.slm.slmbi.dto.QueryInstrumentPanelDTO;
import com.syc.slm.slmbi.entity.InstrumentPanel;
import com.syc.slm.slmbi.vo.InstrumentPanelConfigVo;
import com.syc.slm.slmbi.vo.InstrumentPanelVo;
import com.syc.slm.slmbi.vo.PanelTreeNodeVo;
import lombok.NonNull;
import java.util.List;
......@@ -98,4 +99,8 @@ public interface InstrumentPanelService extends IService<InstrumentPanel> {
* @param panelName
*/
void checkName(@NonNull String appId,String panelId,@NonNull String panelName);
List<InstrumentPanel> getByIds(Set<String> panelIds);
List<PanelTreeNodeVo> selectPanelByIds(Set<String> finalPanelIds,String name);
}
......@@ -2,9 +2,8 @@ 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.InstrumentPanel;
import com.syc.slm.slmbi.entity.InstrumentPanelTree;
import lombok.NonNull;
import com.syc.slm.slmbi.vo.PanelTreeNodeVo;
import java.util.List;
import java.util.Set;
......@@ -58,4 +57,51 @@ public interface InstrumentPanelTreeService extends IService<InstrumentPanelTree
* @param groupId
*/
void updatePanelTreeFullName(String panelId,String panelName,String groupId) ;
/**
* 加载树
* @param appId
* @param name
* @return
*/
List<PanelTreeNodeVo> loadTrees(String appId, String name);
/**
* 加载树
* @param appId
* @return
*/
List<PanelTreeNodeVo> loadTrees(String appId);
/**
* 加载树节点下一节点
* @param groupId
* @param name
* @return
*/
List<PanelTreeNodeVo> children(String groupId, String name);
/**
* 根据仪表板分组id更新 fullId fullName
* @param groupId
* @param panelId
* @param panelName
*/
void updateFullNameByGroupId(String groupId, String panelId, String panelName);
/**
* 复制仪表板配置显示的仪表板树
* @param appId
* @param name
* @return
*/
List<PanelTreeNodeVo> copyTreeList(String appId,String name);
/**
* 复用仪表板树
* @param appId
* @param name
* @return
*/
List<PanelTreeNodeVo> citeTreeList(String appId, String name);
}
......@@ -21,12 +21,15 @@ import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.yaml.snakeyaml.events.Event;
import javax.validation.constraints.NotNull;
import java.net.URLDecoder;
import java.net.URLEncoder;
import java.nio.charset.StandardCharsets;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.stream.Collectors;
/**
......@@ -63,7 +66,7 @@ public class InstrumentPanelConfigServiceImpl extends ServiceImpl<InstrumentPane
@Override
@Transactional(readOnly = true)
public InstrumentPanelConfigVo getConfigByPanelId(String instrumentPanelId) {
InstrumentPanelDraft draft = draftService.getById(instrumentPanelId);
InstrumentPanelDraft draft = draftService.getByPanelId(instrumentPanelId);
return getInstrumentPanelConfigVo(instrumentPanelId,
ObjectUtils.isNotEmpty(draft) ? PublishedStatus.PUBLISHED :
PublishedStatus.WAIT_PUBLISHED);
......@@ -92,7 +95,7 @@ public class InstrumentPanelConfigServiceImpl extends ServiceImpl<InstrumentPane
log.info("更新仪表板树");
updateTree(config, panel);
InstrumentPanelDraft draft = draftService.getById(panel.getId());
InstrumentPanelDraft draft = draftService.getByPanelId(panel.getId());
if (ObjectUtils.isNotEmpty(draft)) {
BeanUtils.copyProperties(panel, draft);
draftService.updateById(draft);
......@@ -115,7 +118,7 @@ public class InstrumentPanelConfigServiceImpl extends ServiceImpl<InstrumentPane
fillPanelProp(permission, panel);
//判断是否有发布版本
InstrumentPanelDraft draft = draftService.getById(panel.getId());
InstrumentPanelDraft draft = draftService.getByPanelId(panel.getId());
if (ObjectUtils.isNotEmpty(draft)) {
log.info("保存配置详情");
savePanelConfig(panel.getId(), config.getConfigDetails(), PublishedStatus.WAIT_PUBLISHED.value);
......@@ -164,13 +167,7 @@ public class InstrumentPanelConfigServiceImpl extends ServiceImpl<InstrumentPane
@Override
public void delConfig(@NotNull String panelId, Integer publishedStatus) {
LambdaQueryWrapper<InstrumentPanelConfig> where = new LambdaQueryWrapper<>();
where.eq(InstrumentPanelConfig::getRecordStatus, SlmConstants.DATA_VALID);
where.eq(InstrumentPanelConfig::getPanelId, panelId);
if (publishedStatus != null) {
where.eq(InstrumentPanelConfig::getPublished, publishedStatus);
}
List<InstrumentPanelConfig> configs = baseMapper.selectList(where);
List<InstrumentPanelConfig> configs = getConfigByPanelIdAndPublishStatus(panelId,publishedStatus);
if (CollectionUtils.isNotEmpty(configs)) {
configs.forEach(x -> {
x.setRecordStatus(SlmConstants.DATA_DELETED);
......@@ -201,27 +198,74 @@ public class InstrumentPanelConfigServiceImpl extends ServiceImpl<InstrumentPane
where.in(InstrumentPanelConfig::getPanelId, ids);
List<InstrumentPanelConfig> configs = baseMapper.selectList(where);
if (CollectionUtils.isNotEmpty(configs)) {
List<InstrumentPanelConfig> waitPublishConfigs =
configs.stream().filter(x -> PublishedStatus.WAIT_PUBLISHED.value.equals(x.getPublished())).collect(
Collectors.toList());
if (CollectionUtils.isNotEmpty(waitPublishConfigs)) {
waitPublishConfigs.forEach(x -> {
x.setPublished(PublishedStatus.PUBLISHED.value);
baseMapper.updateById(x);
});
}
Map<String, List<InstrumentPanelConfig>> configMaps = configs.stream().collect(Collectors.groupingBy(InstrumentPanelConfig::getPanelId));
if(CollectionUtils.isNotEmpty(configMaps)){
configMaps.forEach((k,v)->{
List<InstrumentPanelConfig> waitPublishConfigs = configs.stream().filter(x -> PublishedStatus.WAIT_PUBLISHED.value.equals(x.getPublished())).collect(Collectors.toList());
List<InstrumentPanelConfig> publishConfigs = configs.stream().filter(x -> PublishedStatus.PUBLISHED.value.equals(x.getPublished())).collect(Collectors.toList());
if(CollectionUtils.isNotEmpty(waitPublishConfigs)){
waitPublishConfigs.forEach(x -> {
x.setPublished(PublishedStatus.PUBLISHED.value);
baseMapper.updateById(x);
});
if(CollectionUtils.isNotEmpty(publishConfigs)){
publishConfigs.forEach(x -> {
x.setRecordStatus(SlmConstants.DATA_DELETED);
baseMapper.updateById(x);
});
}
}
List<InstrumentPanelConfig> publishConfigs =
configs.stream().filter(x -> PublishedStatus.PUBLISHED.value.equals(x.getPublished())).collect(
Collectors.toList());
if (CollectionUtils.isNotEmpty(publishConfigs)) {
publishConfigs.forEach(x -> {
x.setRecordStatus(SlmConstants.DATA_DELETED);
baseMapper.updateById(x);
});
}
}
}
@Override
@Transactional(readOnly = true)
public List<InstrumentPanelConfig> getConfigByPanelIdAndPublishStatus(String panelId, Integer publishStatus) {
LambdaQueryWrapper<InstrumentPanelConfig> where = new LambdaQueryWrapper<>();
where.eq(BaseEntity::getRecordStatus, SlmConstants.DATA_VALID);
where.eq(InstrumentPanelConfig::getPanelId, panelId);
if(publishStatus!=null) {
where.eq(InstrumentPanelConfig::getPublished, publishStatus);
}
return baseMapper.selectList(where);
}
@Override
public void offlineConfig(String panelId, Integer publishStatus) {
List<InstrumentPanelConfig> configs = getConfigByPanelIdAndPublishStatus(panelId, publishStatus);
InstrumentPanelConfig waitConfig = configs.stream()
.filter(x -> PublishedStatus.WAIT_PUBLISHED.value.equals(x.getPublished()))
.findFirst()
.orElse(null);
if(ObjectUtils.isNotEmpty(waitConfig)){
InstrumentPanelConfig publishConfig =
configs.stream().filter(x -> PublishedStatus.PUBLISHED.value.equals(x.getPublished())).findFirst().orElse(null);
if(ObjectUtils.isNotEmpty(publishConfig)){
publishConfig.setRecordStatus(SlmConstants.DATA_DELETED);
baseMapper.updateById(publishConfig);
}
}else{
InstrumentPanelConfig pushConfig = configs.stream()
.filter(x -> PublishedStatus.PUBLISHED.value.equals(x.getPublished()))
.findFirst()
.orElse(null);
if(ObjectUtils.isNotEmpty(pushConfig)){
InstrumentPanelConfig config = new InstrumentPanelConfig();
BeanUtils.copyProperties(pushConfig,config);
config.setPublished(PublishedStatus.WAIT_PUBLISHED.value);
config.setId(IdWorker.get32UUID());
baseMapper.insert(config);
pushConfig.setRecordStatus(SlmConstants.DATA_DELETED);
baseMapper.updateById(pushConfig);
}
}
}
private InstrumentPanelConfigVo getInstrumentPanelConfigVo(String instrumentPanelId, PublishedStatus published) {
......
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.extension.service.impl.ServiceImpl;
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,6 +16,7 @@ import com.syc.slm.slmbi.service.InstrumentPanelDraftService;
import org.springframework.stereotype.Service;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.stream.Collectors;
......@@ -28,21 +32,47 @@ public class InstrumentPanelDraftServiceImpl extends ServiceImpl<InstrumentPanel
@Override
public void saveDrafts(List<InstrumentPanel> panels) {
if(CollectionUtils.isNotEmpty(panels)){
List<InstrumentPanelDraft> drafts= SlmConstants.gson.fromJson(SlmConstants.gson.toJson(panels),
new TypeToken<List<InstrumentPanelDraft>>() {
}.getType());
List<InstrumentPanelDraft> panelDrafts = baseMapper.selectBatchIds(panels.stream()
.map(InstrumentPanel::getId)
.collect(Collectors.toList()));
Set<String> idSets= CollectionUtils.isNotEmpty(panelDrafts)?panelDrafts.stream().map(BaseEntity::getId).collect(Collectors.toSet()): Sets.newHashSet();
drafts.forEach(x->{
if(idSets.contains(x.getId())){
baseMapper.updateById(x);
}else{
baseMapper.insert(x);
}
});
if (CollectionUtils.isNotEmpty(panels)) {
List<InstrumentPanelDraft> drafts = SlmConstants.gson.fromJson(SlmConstants.gson.toJson(panels), new TypeToken<List<InstrumentPanelDraft>>() {
}.getType());
if (CollectionUtils.isNotEmpty(drafts)) {
List<InstrumentPanelDraft> panelDrafts = getByIds(panels.stream().map(InstrumentPanel::getId).collect(Collectors.toSet()));
Map<String, String> maps = CollectionUtils.isNotEmpty(panelDrafts) ? panelDrafts.stream().collect(
Collectors.toMap(InstrumentPanelDraft::getPanelId, BaseEntity::getId)) : Maps.newHashMap();
drafts.forEach(x -> {
x.setPanelId(x.getId());
if (maps.containsKey(x.getId())) {
x.setId(maps.get(x.getId()));
baseMapper.updateById(x);
} else {
x.setId(IdWorker.get32UUID());
baseMapper.insert(x);
}
});
}
}
}
@Override
public List<InstrumentPanelDraft> getByIds(Set<String> panelIds) {
LambdaQueryWrapper<InstrumentPanelDraft> where = new LambdaQueryWrapper<>();
where.eq(BaseEntity::getRecordStatus, SlmConstants.DATA_VALID);
where.in(InstrumentPanelDraft::getPanelId, panelIds);
return baseMapper.selectList(where);
}
@Override
public List<InstrumentPanelDraft> selectDraftList(String appId,
Set<String> panelIds,
String officeIds,
String userId,
String roleId) {
return baseMapper.selectDraftList(appId, panelIds, officeIds, userId, roleId);
}
@Override
public InstrumentPanelDraft getByPanelId(String panelId) {
List<InstrumentPanelDraft> drafts = getByIds(Sets.newHashSet(panelId));
return CollectionUtils.isNotEmpty(drafts)?drafts.get(0):null;
}
}
......@@ -13,6 +13,7 @@ import com.syc.slm.slmbi.entity.InstrumentPanelGroup;
import com.syc.slm.slmbi.entity.InstrumentPanelTree;
import com.syc.slm.slmbi.enums.NodeType;
import com.syc.slm.slmbi.exception.SysException;
import com.syc.slm.slmbi.function.Action2;
import com.syc.slm.slmbi.service.InstrumentPanelGroupService;
import com.syc.slm.slmbi.service.InstrumentPanelService;
import com.syc.slm.slmbi.service.InstrumentPanelTreeService;
......@@ -93,49 +94,50 @@ public class InstrumentPanelGroupServiceImpl extends ServiceImpl<InstrumentPanel
tree.setRecordStatus(SlmConstants.DATA_DELETED);
treeService.updateById(tree);
log.info("查询该仪表板树下的子节点");
List<InstrumentPanelTree> instrumentPanelTrees = getInstrumentPanelTrees.apply(tree.getFullId());
List<InstrumentPanelTree> children = getInstrumentPanelTrees.apply(tree.getFullId());
if (CollectionUtils.isNotEmpty(instrumentPanelTrees)) {
Set<String> treeIds = instrumentPanelTrees.stream().map(BaseEntity::getId).collect(Collectors.toSet());
if (CollectionUtils.isNotEmpty(children)) {
Set<String> childrenIds = children.stream().map(BaseEntity::getId).collect(Collectors.toSet());
log.info("删除该仪表板树下的子节点");
treeService.batchUpdateTreeByIds(treeIds, SlmConstants.DATA_DELETED);
treeService.batchUpdateTreeByIds(childrenIds, SlmConstants.DATA_DELETED);
log.info("删除子分组");
delChildrenGroups.accept(instrumentPanelTrees);
delChildrenGroups.accept(children);
log.info("删除各个分组下的仪表板");
delPanelByIds.accept(instrumentPanelTrees);
delPanelByIds.accept(children);
}
return groupId;
}
@Override
@Transactional(rollbackFor = Exception.class)
public String updateGroup(@NonNull InstrumentPanelGroupDTO group) {
public String updateGroup(@NonNull InstrumentPanelGroupDTO group,String appId) {
if(StringUtils.isEmpty(group.getName())){
throw new SysException("仪表板分组名称必填");
}
log.info("检查分组名字是否重复");
checkedRepeatName.accept(group);
InstrumentPanelGroup instrumentPanelGroup = new InstrumentPanelGroup();
BeanUtils.copyProperties(group, instrumentPanelGroup);
baseMapper.updateById(instrumentPanelGroup);
checkedRepeatName.call(group,appId);
InstrumentPanelGroup entity = new InstrumentPanelGroup();
BeanUtils.copyProperties(group, entity);
baseMapper.updateById(entity);
log.info("更新分组在仪表盘树中的全路径");
InstrumentPanelTree tree = treeService.getById(instrumentPanelGroup.getId());
InstrumentPanelTree tree = treeService.getById(entity.getId());
String beforeFullName = tree.getFullName();
String beforeFullId = tree.getFullId();
InstrumentPanelTree panelTree = treeService.getById(group.getParentId());
tree.setFullName(panelTree.getFullName() + "." + instrumentPanelGroup.getName());
tree.setFullId(panelTree.getFullId() + "." + instrumentPanelGroup.getId());
tree.setFullName(panelTree.getFullName() + "." + entity.getName());
tree.setFullId(panelTree.getFullId() + "." + entity.getId());
tree.setName(entity.getName());
treeService.updateById(tree);
log.info("重新构建该分组下的仪表板树全路径");
List<InstrumentPanelTree> instrumentPanelTrees = getInstrumentPanelTrees.apply(beforeFullId);
instrumentPanelTrees.forEach(x -> {
List<InstrumentPanelTree> children = getInstrumentPanelTrees.apply(beforeFullId);
children.forEach(x -> {
x.setFullId(x.getFullId().replace(beforeFullId, tree.getFullId()));
x.setFullName(tree.getFullName()+"." + x.getFullName()
.substring(x.getFullName().lastIndexOf(beforeFullName)));
.substring(beforeFullName.length()+1));
treeService.updateById(x);
});
......@@ -144,52 +146,49 @@ public class InstrumentPanelGroupServiceImpl extends ServiceImpl<InstrumentPanel
@Override
@Transactional(rollbackFor = Exception.class)
public String saveGroup(@NonNull InstrumentPanelGroupDTO group) {
public String saveGroup(@NonNull InstrumentPanelGroupDTO group,String appId) {
if(StringUtils.isEmpty(group.getName())){
throw new SysException("仪表板分组名称必填");
}
log.info("校验名字是否重复");
checkedRepeatName.accept(group);
checkedRepeatName.call(group,appId);
log.info("新增仪表板分组");
InstrumentPanelGroup instrumentPanelGroup = new InstrumentPanelGroup();
BeanUtils.copyProperties(group, instrumentPanelGroup);
instrumentPanelGroup.setId(IdWorker.get32UUID());
baseMapper.insert(instrumentPanelGroup);
InstrumentPanelGroup entity = new InstrumentPanelGroup();
BeanUtils.copyProperties(group, entity);
entity.setId(IdWorker.get32UUID());
baseMapper.insert(entity);
log.info("构建仪表板树 聚合表");
InstrumentPanelTree tree = new InstrumentPanelTree();
tree.setId(instrumentPanelGroup.getId());
tree.setId(entity.getId());
if (StringUtils.isNotEmpty(group.getParentId())) {
InstrumentPanelTree panelTree = treeService.getById(group.getParentId());
if (SlmConstants.DATA_DELETED.equals(panelTree.getRecordStatus())) {
throw new SysException(panelTree.getFullName().substring(group.getParentId().lastIndexOf(".") + 1)
+ ",已不存在,请刷新页面");
throw new SysException(panelTree.getName() + ",已不存在,请刷新页面");
}
tree.setFullId(panelTree.getFullId() + "." + instrumentPanelGroup.getId());
tree.setFullName(panelTree.getFullName() + "." + instrumentPanelGroup.getName());
tree.setFullId(panelTree.getFullId() + "." + entity.getId());
tree.setFullName(panelTree.getFullName() + "." + entity.getName());
} else {
//顶级分组
log.info("重新构建该分组下的仪表板树全路径");
tree.setFullId(instrumentPanelGroup.getId());
tree.setFullName(instrumentPanelGroup.getName());
tree.setFullId(entity.getId());
tree.setFullName(entity.getName());
}
tree.setNodeType(NodeType.GROUP.value);
tree.setName(entity.getName());
treeService.save(tree);
return instrumentPanelGroup.getId();
return entity.getId();
}
@Override
public List<PanelTreeNodeVo> loadTrees(String name) {
return null;
public List<PanelTreeNodeVo> selectGroupByIds(Set<String> finalPanelIds,String name) {
return baseMapper.selectGroupByIds(finalPanelIds,name);
}
@Override
public List<PanelTreeNodeVo> children(String groupId, String name) {
return null;
}
private Consumer<InstrumentPanelGroupDTO> checkedRepeatName = (group) -> {
private Action2<InstrumentPanelGroupDTO,String> checkedRepeatName=(group,appId)-> {
LambdaQueryWrapper<InstrumentPanelGroup> wrapper = new LambdaQueryWrapper<>();
wrapper.eq(InstrumentPanelGroup::getName, group.getName());
wrapper.eq(BaseEntity::getAppId, appId);
wrapper.eq(BaseEntity::getRecordStatus, SlmConstants.DATA_VALID);
if (StringUtils.isNotEmpty(group.getId())) {
wrapper.ne(InstrumentPanelGroup::getId, group.getId());
}
......@@ -198,8 +197,9 @@ public class InstrumentPanelGroupServiceImpl extends ServiceImpl<InstrumentPanel
}
};
private Consumer<List<InstrumentPanelTree>> delChildrenGroups = (instrumentPanelTrees) -> {
Set<String> groupIds = instrumentPanelTrees.stream()
private Consumer<List<InstrumentPanelTree>> delChildrenGroups = (trees) -> {
Set<String> groupIds = trees.stream()
.filter(x -> NodeType.GROUP.value.equals(x.getNodeType()))
.map(BaseEntity::getId)
.collect(Collectors.toSet());
......@@ -210,12 +210,14 @@ public class InstrumentPanelGroupServiceImpl extends ServiceImpl<InstrumentPanel
}
};
private Consumer<List<InstrumentPanelTree>> delPanelByIds = (instrumentPanelTrees) -> {
Set<String> panelIds = instrumentPanelTrees.stream()
private Consumer<List<InstrumentPanelTree>> delPanelByIds = (trees) -> {
Set<String> panelIds = trees.stream()
.filter(x -> NodeType.PANEL.value.equals(x.getNodeType()))
.map(BaseEntity::getId)
.collect(Collectors.toSet());
panelService.batchUpdatePanelByIds(panelIds, SlmConstants.DATA_DELETED);
if(CollectionUtils.isNotEmpty(panelIds)) {
panelService.batchUpdatePanelByIds(panelIds, SlmConstants.DATA_DELETED);
}
};
private Function<String, List<InstrumentPanelTree>> getInstrumentPanelTrees = (fullId) -> {
......
......@@ -3,23 +3,35 @@ 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.Sets;
import com.google.gson.reflect.TypeToken;
import com.syc.slm.common.core.constant.SlmConstants;
import com.syc.slm.slmbi.dao.InstrumentPanelPermissionMapper;
import com.syc.slm.slmbi.dto.CustomPermissionDTO;
import com.syc.slm.slmbi.dto.InstrumentPanelPermissionDTO;
import com.syc.slm.slmbi.entity.InstrumentPanel;
import com.syc.slm.slmbi.entity.InstrumentPanelConfig;
import com.syc.slm.slmbi.entity.InstrumentPanelPermission;
import com.syc.slm.slmbi.enums.AccessType;
import com.syc.slm.slmbi.enums.PublishedStatus;
import com.syc.slm.slmbi.exception.SysException;
import com.syc.slm.slmbi.service.InstrumentPanelPermissionService;
import com.syc.slm.slmbi.service.InstrumentPanelService;
import com.syc.slm.slmbi.service.InstrumentPanelTreeService;
import com.syc.slm.slmbi.vo.CustomPermissionVo;
import com.syc.slm.slmbi.vo.InstrumentPanelPermissionVo;
import lombok.NonNull;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
/**
......@@ -30,42 +42,91 @@ import java.util.stream.Collectors;
* @date : 2021-03-25 19:04
**/
@Service
@Slf4j
public class InstrumentPanelPermissionImpl
extends ServiceImpl<InstrumentPanelPermissionMapper, InstrumentPanelPermission>
implements InstrumentPanelPermissionService {
@Autowired
private InstrumentPanelService panelService;
@Autowired
private InstrumentPanelTreeService treeService;
@Override
@Transactional(rollbackFor = Exception.class)
public String savePermission(InstrumentPanelPermissionDTO permissions) {
//判断仪表板的名称是否重复
//删除原本的权限
//插入现有的权限
//更新仪表板的名称跟分组
return null;
log.info("判断仪表板的名称是否重复");
if (StringUtils.isBlank(permissions.getPanelName())) {
throw new SysException("仪表板名称必填");
}
if (StringUtils.isBlank(permissions.getPanelId())) {
throw new SysException("仪表板id必填,请联系管理员");
}
if (StringUtils.isBlank(permissions.getGroupId())) {
throw new SysException("仪表板groupId必填,请联系管理员");
}
InstrumentPanel panel = panelService.getById(permissions.getPanelId());
panel.setName(permissions.getPanelName());
panel.setGroupId(permissions.getGroupId());
permissions.setAccessType(permissions.getAccessType());
log.info("删除原本的权限");
delPermissionByPanelId(permissions.getPanelId(), PublishedStatus.WAIT_PUBLISHED.value);
savePanelPermission(permissions.getCustomPermissions(),permissions.getPanelId(),permissions.getAccessType(),PublishedStatus.WAIT_PUBLISHED.value);
log.info("更新仪表板的名称跟分组");
treeService.updateFullNameByGroupId(permissions.getGroupId(),permissions.getPanelId(),permissions.getPanelName());
panelService.updateById(panel);
return permissions.getPanelId();
}
@Override
public List<InstrumentPanelPermissionVo> saveCopyOtherPermission(@NonNull String instrumentPanelId) {
return null;
public InstrumentPanelPermissionVo saveCopyOtherPermission(@NonNull String instrumentPanelId) {
return selectPermissionByPanelId(instrumentPanelId);
}
@Override
public String saveCopyToOtherPermission(InstrumentPanelPermissionDTO permissions, String otherInstrumentPanelId) {
return null;
@Transactional(rollbackFor = Exception.class)
public void saveCopyToOtherPermission(InstrumentPanelPermissionDTO permissions, List<String> otherInstrumentPanelIds) {
if(CollectionUtils.isEmpty(otherInstrumentPanelIds)){
throw new SysException("其他仪表板id必填,请联系管理员");
}
if(StringUtils.isBlank(permissions.getAccessType())){
throw new SysException("访问权限类型必填");
}
List<InstrumentPanel> panels = panelService.getByIds(Sets.newHashSet(otherInstrumentPanelIds));
panels.forEach(panel->{
panel.setAccessPermission(permissions.getAccessType());
log.info("删除原本的权限");
delPermissionByPanelId(permissions.getPanelId(), PublishedStatus.WAIT_PUBLISHED.value);
log.info("插入现有的权限");
savePanelPermission(permissions.getCustomPermissions(), panel.getId(), panel.getAccessPermission(), PublishedStatus.WAIT_PUBLISHED.value);
log.info("更新访问权限");
panelService.updateById(panel);
});
}
@Override
public List<InstrumentPanelPermissionVo> selectPermissionByPanelId(@NonNull String instrumentPanelId) {
return null;
@Transactional(readOnly = true)
public InstrumentPanelPermissionVo selectPermissionByPanelId(@NonNull String instrumentPanelId) {
InstrumentPanelPermissionVo vo = new InstrumentPanelPermissionVo();
InstrumentPanel panel = panelService.getById(instrumentPanelId);
vo.setAccessType(panel.getAccessPermission());
List<CustomPermissionVo> vos = getPublishPermissionByPanelId(instrumentPanelId, PublishedStatus.WAIT_PUBLISHED.value);
if(CollectionUtils.isEmpty(vos)){
vos = getPublishPermissionByPanelId(instrumentPanelId, PublishedStatus.PUBLISHED.value);
}
vo.setCustomPermissions(vos);
return vo;
}
@Override
public void delPermissionByPanelId(@NonNull String panelId,Integer publishStatus) {
LambdaQueryWrapper<InstrumentPanelPermission> where = new LambdaQueryWrapper<>();
where.eq(InstrumentPanelPermission::getPanelId, panelId);
where.eq(InstrumentPanelPermission::getRecordStatus, SlmConstants.DATA_VALID);
if(publishStatus!=null){
where.eq(InstrumentPanelPermission::getPublished, publishStatus);
}
List<InstrumentPanelPermission> permissions = baseMapper.selectList(where);
public void delPermissionByPanelId(@NonNull String panelId, Integer publishStatus) {
List<InstrumentPanelPermission> permissions =getPermissionByPanelIdAndPublishStatus(panelId,publishStatus);
if (CollectionUtils.isNotEmpty(permissions)) {
permissions.forEach(x -> {
x.setRecordStatus(SlmConstants.DATA_DELETED);
......@@ -76,21 +137,18 @@ public class InstrumentPanelPermissionImpl
@Override
@Transactional(readOnly = true)
public List<CustomPermissionVo> getPublishPermissionByPanelId(@NonNull String panelId,@NonNull Integer publishStatus) {
LambdaQueryWrapper<InstrumentPanelPermission> where = new LambdaQueryWrapper<>();
where.eq(InstrumentPanelPermission::getPanelId, panelId);
where.eq(InstrumentPanelPermission::getRecordStatus, SlmConstants.DATA_VALID);
where.eq(InstrumentPanelPermission::getPublished, publishStatus);
List<InstrumentPanelPermission> permissions = baseMapper.selectList(where);
return CollectionUtils.isNotEmpty(permissions) ?
SlmConstants.gson.fromJson(SlmConstants.gson.toJson(permissions),
new TypeToken<List<CustomPermissionVo>>() {
}.getType()) : null;
public List<CustomPermissionVo> getPublishPermissionByPanelId(@NonNull String panelId,
@NonNull Integer publishStatus) {
List<InstrumentPanelPermission> permissions = getPermissionByPanelIdAndPublishStatus(panelId,publishStatus);
return CollectionUtils.isNotEmpty(permissions) ? SlmConstants.gson.fromJson(SlmConstants.gson.toJson(permissions), new TypeToken<List<CustomPermissionVo>>() {}.getType()) : null;
}
@Override
public void savePanelPermission(List<CustomPermissionDTO> customPermissions,String panelId,String accessType,Integer publishStatus) {
if(CollectionUtils.isNotEmpty(customPermissions)){
public void savePanelPermission(List<CustomPermissionDTO> customPermissions,
String panelId,
String accessType,
Integer publishStatus) {
if (CollectionUtils.isNotEmpty(customPermissions)) {
if (AccessType.CUSTOM.value.equals(accessType)) {
if (CollectionUtils.isNotEmpty(customPermissions)) {
customPermissions.forEach(x -> {
......@@ -114,22 +172,64 @@ public class InstrumentPanelPermissionImpl
where.in(InstrumentPanelPermission::getPanelId, ids);
where.eq(InstrumentPanelPermission::getRecordStatus, SlmConstants.DATA_VALID);
List<InstrumentPanelPermission> permissions = baseMapper.selectList(where);
if(CollectionUtils.isNotEmpty(permissions)){
List<InstrumentPanelPermission> waitPublishPermission =
permissions.stream().filter(x -> PublishedStatus.WAIT_PUBLISHED.value.equals(x.getPublished())).collect(Collectors.toList());
if(CollectionUtils.isNotEmpty(waitPublishPermission)){
waitPublishPermission.forEach(x->{
x.setPublished(PublishedStatus.PUBLISHED.value);
Map<String, List<InstrumentPanelPermission>> permissionMaps = permissions.stream().collect(Collectors.groupingBy(InstrumentPanelPermission::getPanelId));
if(CollectionUtils.isNotEmpty(permissionMaps)){
permissionMaps.forEach((k,v)->{
List<InstrumentPanelPermission> waitings = permissions.stream().filter(x -> PublishedStatus.WAIT_PUBLISHED.value.equals(x.getPublished())).collect(Collectors.toList());
List<InstrumentPanelPermission> publishs = permissions.stream().filter(x -> PublishedStatus.PUBLISHED.value.equals(x.getPublished())).collect(Collectors.toList());
if (CollectionUtils.isNotEmpty(waitings)) {
waitings.forEach(x -> {
x.setPublished(PublishedStatus.PUBLISHED.value);
baseMapper.updateById(x);
});
if (CollectionUtils.isNotEmpty(publishs)) {
publishs.forEach(x -> {
x.setRecordStatus(SlmConstants.DATA_DELETED);
baseMapper.updateById(x);
});
}
}
});
}
}
@Override
public List<InstrumentPanelPermission> getPermissionByPanelIdAndPublishStatus(String panelId, Integer publishStatus) {
LambdaQueryWrapper<InstrumentPanelPermission> where = new LambdaQueryWrapper<>();
where.eq(InstrumentPanelPermission::getPanelId, panelId);
where.eq(InstrumentPanelPermission::getRecordStatus, SlmConstants.DATA_VALID);
if(publishStatus!=null) {
where.eq(InstrumentPanelPermission::getPublished, publishStatus);
}
return baseMapper.selectList(where);
}
@Override
public void offlinePermission(String panelId) {
List<InstrumentPanelPermission> permissions = getPermissionByPanelIdAndPublishStatus(panelId,null);
long waitP = permissions.stream().filter(x -> PublishedStatus.WAIT_PUBLISHED.value.equals(x.getPublished())).count();
List<InstrumentPanelPermission> publish = permissions.stream().filter(x -> PublishedStatus.PUBLISHED.value.equals(x.getPublished())).collect(Collectors.toList());
if(waitP>0){
if(CollectionUtils.isNotEmpty(publish)){
publish.forEach(x->{
x.setRecordStatus(SlmConstants.DATA_DELETED);
baseMapper.updateById(x);
});
}
List<InstrumentPanelPermission> publishPermission =
permissions.stream().filter(x -> PublishedStatus.PUBLISHED.value.equals(x.getPublished())).collect(Collectors.toList());
if(CollectionUtils.isNotEmpty(publishPermission)){
publishPermission.forEach(x->{
x.setRecordStatus(SlmConstants.DATA_DELETED);
baseMapper.updateById(x);
}else{
if(CollectionUtils.isNotEmpty(publish)){
publish.forEach(push->{
InstrumentPanelPermission p = new InstrumentPanelPermission();
BeanUtils.copyProperties(push, p);
p.setPublished(PublishedStatus.WAIT_PUBLISHED.value);
p.setId(IdWorker.get32UUID());
baseMapper.insert(p);
push.setRecordStatus(SlmConstants.DATA_DELETED);
baseMapper.updateById(push);
});
}
}
}
......
......@@ -22,6 +22,7 @@ import com.syc.slm.slmbi.exception.SysException;
import com.syc.slm.slmbi.service.*;
import com.syc.slm.slmbi.vo.InstrumentPanelConfigVo;
import com.syc.slm.slmbi.vo.InstrumentPanelVo;
import com.syc.slm.slmbi.vo.PanelTreeNodeVo;
import lombok.NonNull;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
......@@ -57,31 +58,31 @@ public class InstrumentPanelServiceImpl extends ServiceImpl<InstrumentPanelMappe
@Override
@Transactional(readOnly = true)
public IPage<InstrumentPanelVo> selectInstrumentPanelList(String appId, QueryInstrumentPanelDTO where) {
IPage<InstrumentPanelVo> page = new Page<>(where.getPageNum(), where.getPageSize());
QueryWrapper<InstrumentPanel> wrapper = new QueryWrapper<>();
wrapper.eq("p.app_id", appId);
wrapper.eq("p.group_id", where.getGroupId());
wrapper.eq("p.record_status", SlmConstants.DATA_VALID);
if (StringUtils.isNotEmpty(where.getName())) {
wrapper.like("p.name", where.getName());
public IPage<InstrumentPanelVo> selectInstrumentPanelList(String appId, QueryInstrumentPanelDTO query) {
IPage<InstrumentPanelVo> page = new Page<>(query.getCurrent(), query.getSize());
QueryWrapper<InstrumentPanel> where = new QueryWrapper<>();
where.eq("p.app_id", appId);
where.eq("p.group_id", query.getGroupId());
where.eq("p.record_status", SlmConstants.DATA_VALID);
if (StringUtils.isNotEmpty(query.getName())) {
where.like("p.name", query.getName());
}
if (StringUtils.isNotEmpty(where.getCreatorName())) {
wrapper.like("p.creator_name", where.getCreatorName());
if (StringUtils.isNotEmpty(query.getCreatorName())) {
where.like("p.creator_name", query.getCreatorName());
}
if (StringUtils.isNotEmpty(where.getUpdaterName())) {
wrapper.like("p.updater_name", where.getUpdaterName());
if (StringUtils.isNotEmpty(query.getUpdaterName())) {
where.like("p.updater_name", query.getUpdaterName());
}
if (where.getPublished() != null) {
wrapper.eq("p.published", where.getPublished());
if (query.getPublished() != null) {
where.eq("p.published", query.getPublished());
}
if (where.getUpdateTimeBegin() != null) {
wrapper.gt("p.update_time", where.getUpdateTimeBegin());
if (query.getUpdateTimeBegin() != null) {
where.ge("p.update_time", query.getUpdateTimeBegin());
}
if (where.getUpdateTimeEnd() != null) {
wrapper.lt("p.update_time", where.getUpdateTimeEnd());
if (query.getUpdateTimeEnd() != null) {
where.le("p.update_time", query.getUpdateTimeEnd());
}
return baseMapper.selectInstrumentPanelList(page, wrapper);
return baseMapper.selectInstrumentPanelList(page, where);
}
@Override
......@@ -129,9 +130,8 @@ public class InstrumentPanelServiceImpl extends ServiceImpl<InstrumentPanelMappe
log.info("删除该仪表板下的配置");
delAllSetting(id);
log.info("删除仪表板草稿表");
InstrumentPanelDraft draft = new InstrumentPanelDraft();
InstrumentPanelDraft draft =draftService.getByPanelId(id);
draft.setRecordStatus(SlmConstants.DATA_DELETED);
draft.setId(id);
draftService.updateById(draft);
return id;
}
......@@ -146,7 +146,7 @@ public class InstrumentPanelServiceImpl extends ServiceImpl<InstrumentPanelMappe
@Override
@Transactional(readOnly = true)
public Boolean showRecoveryBtn(String id) {
return draftService.getById(id) != null;
return draftService.getByPanelId(id) != null;
}
@Override
......@@ -168,14 +168,22 @@ public class InstrumentPanelServiceImpl extends ServiceImpl<InstrumentPanelMappe
if (SlmConstants.DATA_DELETED.equals(panel.getRecordStatus())) {
throw new SysException("该数据已被删除,请刷新页面");
}
panel.setPublished(PublishedStatus.OFFLINE.value);
// panel.setRecordStatus(SlmConstants.DATA_DELETED);
if(PublishedStatus.WAIT_PUBLISHED.value.equals(panel.getPublished())){
throw new SysException("该仪表板已被下线,请刷新页面");
}
panel.setPublished(PublishedStatus.WAIT_PUBLISHED.value);
baseMapper.updateById(panel);
// log.info("删除配置");
// log.info("删除权限");
// log.info("删除草稿");
// log.info("删除仪表板树");
// delAllSetting(id);
log.info("删除草稿");
InstrumentPanelDraft draft = draftService.getByPanelId(panel.getId());
if(ObjectUtils.isNotEmpty(draft)){
draft.setRecordStatus(SlmConstants.DATA_DELETED);
draftService.updateById(draft);
}
log.info("更新仪表板配置为待发布状态");
configService.offlineConfig(panel.getId(), null);
log.info("更新仪表板权限为待发布状态");
permissionService.offlinePermission(panel.getId());
return id;
}
......@@ -200,6 +208,16 @@ public class InstrumentPanelServiceImpl extends ServiceImpl<InstrumentPanelMappe
}
}
@Override
public List<InstrumentPanel> getByIds(Set<String> panelIds) {
return baseMapper.selectBatchIds(panelIds);
}
@Override
public List<PanelTreeNodeVo> selectPanelByIds(Set<String> finalPanelIds,String name) {
return baseMapper.selectPanelByIds(finalPanelIds,name);
}
private String savePanelData(String appId, SaveInstrumentPanelDTO panel) {
if (StringUtils.isEmpty(panel.getName())) {
throw new SysException("仪表板名字必填");
......@@ -213,21 +231,11 @@ public class InstrumentPanelServiceImpl extends ServiceImpl<InstrumentPanelMappe
log.info("保存仪表板访问权限");
String panelId = IdWorker.get32UUID();
String accessType = AccessType.PUBLIC.value;
if (ObjectUtils.isNotEmpty(panel.getPermission()) && StringUtils.isNotEmpty(panel.getPermission()
.getAccessType())) {
if (ObjectUtils.isNotEmpty(panel.getPermission()) && StringUtils.isNotEmpty(panel.getPermission().getAccessType())) {
accessType = panel.getPermission().getAccessType();
permissionService.savePanelPermission(panel.getPermission().getCustomPermissions(),
panelId,
panel.getPermission().getAccessType(),
PublishedStatus.WAIT_PUBLISHED.value);
permissionService.savePanelPermission(panel.getPermission().getCustomPermissions(),panelId,panel.getPermission().getAccessType(),PublishedStatus.WAIT_PUBLISHED.value);
}
InstrumentPanel instrumentPanel = new InstrumentPanel(panelId,
panel.getName(),
panel.getGroupId(),
accessType,
PublishedStatus.WAIT_PUBLISHED.value);
InstrumentPanel entity = new InstrumentPanel(panelId,panel.getName(),panel.getGroupId(),accessType,PublishedStatus.WAIT_PUBLISHED.value);
log.info("保存仪表板配置");
if (StringUtils.isNotEmpty(panel.getConfigDetails())) {
......@@ -235,20 +243,17 @@ public class InstrumentPanelServiceImpl extends ServiceImpl<InstrumentPanelMappe
}
log.info("初始化仪表板树");
treeService.initTree(instrumentPanel.getGroupId(),
NodeType.PANEL.value,
instrumentPanel.getId(),
instrumentPanel.getName());
treeService.initTree(entity.getGroupId(),NodeType.PANEL.value,entity.getId(),entity.getName());
if (CollectionUtils.isNotEmpty(panel.getAssemblys())) {
InstrumentPanelTree tree = treeService.getById(instrumentPanel.getId());
InstrumentPanelTree tree = treeService.getById(entity.getId());
log.info("保存仪表板组件树");
treeService.savePanelAssemblyTree(tree, panel.getAssemblys(), instrumentPanel.getId());
treeService.savePanelAssemblyTree(tree, panel.getAssemblys(), entity.getId());
} else {
log.info("前端没有构建组件树");
}
log.info("保存仪表板数据");
baseMapper.insert(instrumentPanel);
baseMapper.insert(entity);
return panelId;
}
......
......@@ -2,20 +2,33 @@ 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.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.Sets;
import com.google.gson.reflect.TypeToken;
import com.syc.slm.common.core.constant.SlmConstants;
import com.syc.slm.slmbi.dao.InstrumentPanelTreeMapper;
import com.syc.slm.slmbi.dto.InstrumentPanelAssemblyDTO;
import com.syc.slm.slmbi.entity.BaseEntity;
import com.syc.slm.slmbi.entity.InstrumentPanel;
import com.syc.slm.slmbi.entity.InstrumentPanelTree;
import com.syc.slm.slmbi.entity.*;
import com.syc.slm.slmbi.enums.NodeType;
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.vo.CustomPermissionVo;
import com.syc.slm.slmbi.vo.InstrumentPanelGroupVo;
import com.syc.slm.slmbi.vo.PanelTreeNodeVo;
import lombok.NonNull;
import org.apache.commons.io.filefilter.FalseFileFilter;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.util.List;
import java.util.Set;
import java.util.*;
import java.util.stream.Collectors;
/**
* 仪表板树聚合表
......@@ -27,10 +40,18 @@ import java.util.Set;
public class InstrumentPanelTreeServiceImpl extends ServiceImpl<InstrumentPanelTreeMapper, InstrumentPanelTree>
implements InstrumentPanelTreeService {
@Autowired
private InstrumentPanelDraftService draftService;
@Autowired
private InstrumentPanelGroupService groupService;
@Autowired
private InstrumentPanelService panelService;
@Override
public void batchUpdateTreeByIds(Set<String> treeIds, Integer recordStatus) {
if(CollectionUtils.isNotEmpty(treeIds)){
baseMapper.batchUpdateTreeByIds(treeIds,recordStatus);
if (CollectionUtils.isNotEmpty(treeIds)) {
baseMapper.batchUpdateTreeByIds(treeIds, recordStatus);
}
}
......@@ -42,6 +63,7 @@ public class InstrumentPanelTreeServiceImpl extends ServiceImpl<InstrumentPanelT
tree.setNodeType(nodeType);
tree.setFullName(panelTree.getFullName() + "." + bizName);
tree.setFullId(panelTree.getFullId() + "." + bizId);
tree.setName(bizName);
baseMapper.insert(tree);
}
......@@ -50,13 +72,12 @@ public class InstrumentPanelTreeServiceImpl extends ServiceImpl<InstrumentPanelT
InstrumentPanelTree tree = baseMapper.selectById(panelId);
tree.setRecordStatus(SlmConstants.DATA_DELETED);
baseMapper.updateById(tree);
//#todo 仪表板组件树
LambdaQueryWrapper<InstrumentPanelTree> where = new LambdaQueryWrapper<>();
where.eq(BaseEntity::getRecordStatus, SlmConstants.DATA_VALID);
where.likeRight(InstrumentPanelTree::getFullId,tree.getFullId()+".");
where.likeRight(InstrumentPanelTree::getFullId, tree.getFullId() + ".");
List<InstrumentPanelTree> list = baseMapper.selectList(where);
if(CollectionUtils.isNotEmpty(list)){
list.forEach(x->{
if (CollectionUtils.isNotEmpty(list)) {
list.forEach(x -> {
x.setRecordStatus(SlmConstants.DATA_DELETED);
baseMapper.updateById(x);
});
......@@ -65,14 +86,18 @@ public class InstrumentPanelTreeServiceImpl extends ServiceImpl<InstrumentPanelT
@Override
public void savePanelAssemblyTree(InstrumentPanelTree tree,List<InstrumentPanelAssemblyDTO> assembly,String panelId) {
if(CollectionUtils.isNotEmpty(assembly)){
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不能为空,请联系管理员");
}
InstrumentPanelTree t = new InstrumentPanelTree();
t.setId(tree.getId() + "_" + i);
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());
baseMapper.insert(t);
}
}
......@@ -85,19 +110,279 @@ public class InstrumentPanelTreeServiceImpl extends ServiceImpl<InstrumentPanelT
where.eq(BaseEntity::getRecordStatus, SlmConstants.DATA_VALID);
where.likeRight(InstrumentPanelTree::getFullId, fullId + ".");
List<InstrumentPanelTree> trees = baseMapper.selectList(where);
if(CollectionUtils.isNotEmpty(trees)){
trees.forEach(x->{
if (CollectionUtils.isNotEmpty(trees)) {
trees.forEach(x -> {
x.setRecordStatus(SlmConstants.DATA_DELETED);
baseMapper.updateById(x);
});
}
}
@Override
public void updatePanelTreeFullName(String panelId,String panelName,String groupId) {
public void updatePanelTreeFullName(String panelId, String panelName, String groupId) {
InstrumentPanelTree groupTree = baseMapper.selectById(groupId);
InstrumentPanelTree tree = baseMapper.selectById(panelId);
tree.setFullName(groupTree.getFullName() + "." + panelName);
tree.setFullId(groupTree.getFullId() + "." + panelId);
tree.setName(panelName);
baseMapper.updateById(tree);
}
@Override
public List<PanelTreeNodeVo> loadTrees(String appId, String name) {
if(StringUtils.isBlank(name)){
return loadTrees(appId);
}
List<PanelTreeNodeVo> lists = Lists.newArrayList();
String officeIds = null;
String userId = null;
String roleId = null;
LambdaQueryWrapper<InstrumentPanelTree> where = new LambdaQueryWrapper<>();
where.eq(BaseEntity::getAppId, appId);
where.eq(BaseEntity::getRecordStatus, SlmConstants.DATA_VALID);
where.eq(InstrumentPanelTree::getNodeType, NodeType.PANEL.value);
if (StringUtils.isNotBlank(name)) {
where.like(InstrumentPanelTree::getFullName, name);
}
List<InstrumentPanelTree> trees = baseMapper.selectList(where);
if (CollectionUtils.isNotEmpty(trees)) {
Set<String> panelIds = trees.stream().map(BaseEntity::getId).collect(Collectors.toSet());
List<InstrumentPanelDraft> panels = draftService.selectDraftList(appId, panelIds, officeIds, userId, roleId);
if (CollectionUtils.isNotEmpty(panels)) {
Set<String> publishIds = panels.stream().map(InstrumentPanelDraft::getPanelId).collect(Collectors.toSet());
Set<String[]> finalPanelArrays = trees.stream()
.filter(x -> publishIds.contains(x.getId()))
.map(x -> x.getFullId().split("[.]"))
.collect(Collectors.toSet());
Set<String> finalPanelIds = Sets.newHashSet();
finalPanelArrays.forEach(x-> finalPanelIds.addAll(Arrays.asList(x)));
List<PanelTreeNodeVo> panelTreeNodeVos = panelService.selectPanelByIds(finalPanelIds,name);
if (CollectionUtils.isNotEmpty(panelTreeNodeVos)) {
lists.addAll(panelTreeNodeVos);
}
List<PanelTreeNodeVo> groupTreeNodeVos = groupService.selectGroupByIds(finalPanelIds,null);
if (CollectionUtils.isNotEmpty(groupTreeNodeVos)) {
if(CollectionUtils.isEmpty(panelTreeNodeVos) && StringUtils.isNotBlank(name)){
Set<String> groupIds = groupTreeNodeVos.stream().filter(x -> x.getName().contains(name)).map(PanelTreeNodeVo::getId).collect(Collectors.toSet());
List<InstrumentPanelTree> groupTrees = baseMapper.selectBatchIds(groupIds);
groupIds.clear();
groupTrees.forEach(x->{
if(x.getFullId().contains(".")){
groupIds.addAll(Arrays.asList(x.getFullId().split("[.]")));
}else{
groupIds.add(x.getFullId());
}
});
groupTreeNodeVos= groupService.selectGroupByIds(groupIds,null);
}
lists.addAll(groupTreeNodeVos);
}
}
}
return lists;
}
@Override
public List<PanelTreeNodeVo> loadTrees(String appId) {
List<PanelTreeNodeVo> lists = Lists.newArrayList();
String officeIds=null;
String userId=null;
String roleId=null;
LambdaQueryWrapper<InstrumentPanelTree> where = new LambdaQueryWrapper<>();
where.eq(BaseEntity::getAppId, appId);
where.eq(BaseEntity::getRecordStatus, SlmConstants.DATA_VALID);
where.eq(InstrumentPanelTree::getNodeType, NodeType.PANEL.value);
List<InstrumentPanelTree> trees = baseMapper.selectList(where);
if (CollectionUtils.isNotEmpty(trees)) {
Set<String> panelIds = trees.stream().map(BaseEntity::getId).collect(Collectors.toSet());
List<InstrumentPanelDraft> panels = draftService.selectDraftList(appId,panelIds,officeIds,userId,roleId);
if(CollectionUtils.isNotEmpty(panels)) {
Set<String> publishIds = panels.stream().map(InstrumentPanelDraft::getPanelId).collect(Collectors.toSet());
Set<String[]> finalPanelArrays = trees.stream()
.filter(x -> publishIds.contains(x.getId()))
.map(x -> x.getFullId().split("[.]"))
.collect(Collectors.toSet());
Set<String> finalPanelIds = Sets.newHashSet();
finalPanelArrays.forEach(x -> {
if (x.length > 3) {
for (int i = 0; i < x.length; i++) {
if (i == 2) {
break;
}
finalPanelIds.add(x[i]);
}
}
});
List<PanelTreeNodeVo> groupTreeNodeVos = groupService.selectGroupByIds(finalPanelIds,null);
if (CollectionUtils.isNotEmpty(groupTreeNodeVos)) {
lists.addAll(groupTreeNodeVos);
}
List<PanelTreeNodeVo> panelTreeNodeVos = panelService.selectPanelByIds(finalPanelIds,null);
if (CollectionUtils.isNotEmpty(panelTreeNodeVos)) {
lists.addAll(panelTreeNodeVos);
} else {
if (CollectionUtils.isNotEmpty(groupTreeNodeVos)) {
String groupId = groupTreeNodeVos.stream().filter(x->StringUtils.isNotBlank(x.getParentId())).findFirst().get().getId();
boolean flag = true;
int num =0;
while (flag) {
if(num>10){
break;
}
num++;
List<PanelTreeNodeVo> childrenNodes = this.children(groupId, null);
if(CollectionUtils.isEmpty(childrenNodes)){
flag=false;
}
long count = childrenNodes.stream()
.filter(x -> NodeType.PANEL.value.equals(x.getNodeType()))
.count();
if (count == 0) {
lists.addAll(childrenNodes);
groupId = childrenNodes.stream()
.filter(x -> NodeType.GROUP.value.equals(x.getNodeType()))
.findFirst()
.get()
.getId();
} else {
flag = false;
lists.addAll(childrenNodes);
}
}
}
}
}
}
return lists;
}
@Override
@Transactional(readOnly = true)
public List<PanelTreeNodeVo> children(String groupId, String name) {
List<PanelTreeNodeVo> lists = Lists.newArrayList();
String officeIds = null;
String userId = null;
String roleId = null;
InstrumentPanelTree tree = baseMapper.selectById(groupId);
LambdaQueryWrapper<InstrumentPanelTree> where = new LambdaQueryWrapper<>();
where.likeRight(InstrumentPanelTree::getFullId, tree.getFullId() + ".");
where.eq(BaseEntity::getRecordStatus, SlmConstants.DATA_VALID);
if (StringUtils.isNotBlank(name)) {
where.like(InstrumentPanelTree::getFullName, name);
}
where.eq(InstrumentPanelTree::getNodeType, NodeType.PANEL.value);
List<InstrumentPanelTree> trees = baseMapper.selectList(where);
if (CollectionUtils.isNotEmpty(trees)) {
Set<String> panelIds = trees.stream().map(BaseEntity::getId).collect(Collectors.toSet());
List<InstrumentPanelDraft> panels = draftService.selectDraftList(tree.getAppId(),
panelIds,
officeIds,
userId,
roleId);
if (CollectionUtils.isNotEmpty(panels)) {
Set<String> publishIds = panels.stream().map(InstrumentPanelDraft::getPanelId).collect(Collectors.toSet());
Set<String> finalPanelIds = trees.stream().filter(x -> publishIds.contains(x.getId())).map(x -> {
String fullId = x.getFullId();
fullId = fullId.replace(tree.getFullId() + ".", "");
if (fullId.contains(".")) {
return fullId.substring(0, fullId.indexOf("."));
} else {
return fullId;
}
}).collect(Collectors.toSet());
if (CollectionUtils.isNotEmpty(finalPanelIds)) {
List<PanelTreeNodeVo> panelTreeNodeVos = panelService.selectPanelByIds(finalPanelIds, name);
if (CollectionUtils.isNotEmpty(panelTreeNodeVos)) {
lists.addAll(panelTreeNodeVos);
finalPanelIds.addAll(panelTreeNodeVos.stream()
.filter(x -> !groupId.equals(x.getParentId()))
.map(PanelTreeNodeVo::getParentId)
.collect(Collectors.toSet()));
}
List<PanelTreeNodeVo> groupTreeNodeVos = groupService.selectGroupByIds(finalPanelIds, name);
if (CollectionUtils.isNotEmpty(groupTreeNodeVos)) {
lists.addAll(groupTreeNodeVos);
}
}
}
}
return lists;
}
@Override
public void updateFullNameByGroupId(String groupId, String panelId, String panelName) {
InstrumentPanelTree group = baseMapper.selectById(groupId);
InstrumentPanelTree panelTree = baseMapper.selectById(panelId);
String beforeFullName = panelTree.getFullName();
String beforeFullId = panelTree.getFullId();
if(ObjectUtils.isNotEmpty(group)){
LambdaQueryWrapper<InstrumentPanelTree> where = new LambdaQueryWrapper<>();
where.eq(BaseEntity::getRecordStatus, SlmConstants.DATA_VALID);
where.likeRight(InstrumentPanelTree::getFullId, group.getFullId() + ".");
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.setName(name);
baseMapper.updateById(x);
});
}
}
}
@Override
@Transactional(readOnly = true)
public List<PanelTreeNodeVo> copyTreeList(String appId,String name) {
return getCopyAndCiteTrees(appId, name, false);
}
@Override
@Transactional(readOnly = true)
public List<PanelTreeNodeVo> citeTreeList(String appId, String name) {
return getCopyAndCiteTrees(appId, name, true);
}
private List<PanelTreeNodeVo> getCopyAndCiteTrees(String appId, String name,boolean showAssembly) {
LambdaQueryWrapper<InstrumentPanelTree> where = new LambdaQueryWrapper<>();
where.eq(BaseEntity::getAppId, appId);
where.eq(BaseEntity::getRecordStatus, SlmConstants.DATA_VALID);
if(!showAssembly){
where.eq(InstrumentPanelTree::getNodeType, NodeType.ASSEMBLY.value);
}
List<InstrumentPanelTree> allGroups=baseMapper.selectList(where);
List<InstrumentPanelTree> filteredTrees=allGroups;
Map<String, InstrumentPanelTree> allMaps=allGroups.stream().collect(Collectors.toMap(InstrumentPanelTree::getFullId, x->x));
Map<String, InstrumentPanelTree> filteredMaps=allMaps;
where.like(InstrumentPanelTree::getName, name);
if(StringUtils.isNotBlank(name)){
filteredTrees=baseMapper.selectList(where);
filteredMaps=filteredTrees.stream().collect(Collectors.toMap(InstrumentPanelTree::getFullId, x->x));
}
Stack<InstrumentPanelTree> stack=new Stack<>();
stack.addAll(filteredTrees);
while(!stack.isEmpty()){
InstrumentPanelTree tree = stack.pop();
String fullId=tree.getFullId();
int lastDot=fullId.lastIndexOf(".");
String pid=fullId;
while(lastDot>0){
pid=pid.substring(0, lastDot);
InstrumentPanelTree pTree= Optional.ofNullable(filteredMaps.get(pid)).orElse(allMaps.get(pid));
if(pTree!=null){
tree.setParentId(pid.substring(pid.lastIndexOf(".")+1));
filteredMaps.putIfAbsent(pid, pTree);
stack.add(pTree);
break;
}
lastDot=pid.lastIndexOf(".");
}
}
return CollectionUtils.isNotEmpty(filteredMaps.values())?SlmConstants.gson.fromJson(SlmConstants.gson.toJson(filteredMaps.values()), new TypeToken<List<PanelTreeNodeVo>>() {}.getType()):
Lists.newArrayList();
}
}
package com.syc.slm.slmbi.vo;
import com.syc.slm.slmbi.dto.CustomPermissionDTO;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.EqualsAndHashCode;
import java.util.List;
/**
* slm-bi
* 仪表板权限vo
......@@ -16,10 +19,10 @@ import lombok.EqualsAndHashCode;
@ApiModel(value = "仪表板权限Vo",description = "仪表板权限Vo")
@EqualsAndHashCode(callSuper=false)
public class InstrumentPanelPermissionVo {
@ApiModelProperty(value = "存储类型,1代表岗位,2代表部门,3 代表个体用户")
private Integer permissionType;
@ApiModelProperty(value = "代表岗位,部门,个体用户id")
private String bizId;
@ApiModelProperty(value = "代表岗位,部门,个体用户名称")
private String bizName;
@ApiModelProperty(value = "访问权限类型", required = true)
private String accessType;
@ApiModelProperty(value = "自定义权限配置,当访问类型为CUSTOM时必填")
private List<CustomPermissionVo> customPermissions;
}
......@@ -24,5 +24,7 @@ public class PanelTreeNodeVo {
@ApiModelProperty(value = "节点名称")
private String name;
@ApiModelProperty(value = "节点类型")
private PanelTreeNodeType type;
private String nodeType;
@ApiModelProperty(value = "组件对应key,分组跟仪表板该字段为空")
private String assemblyKey;
}
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