Skip to content

Commit

Permalink
feat(plugin handle): (#307)
Browse files Browse the repository at this point in the history
plugin handle manage
  • Loading branch information
241600489 authored Sep 16, 2020
1 parent d708c66 commit 14a888b
Show file tree
Hide file tree
Showing 13 changed files with 668 additions and 2 deletions.
16 changes: 16 additions & 0 deletions script/soul.sql
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,22 @@ CREATE TABLE IF NOT EXISTS `auth_path` (
PRIMARY KEY (`id`) USING BTREE
) ENGINE = InnoDB CHARACTER SET = utf8mb4 COLLATE = utf8mb4_unicode_ci ROW_FORMAT = Dynamic;

-- ----------------------------
-- Table structure for plugin_handle
-- ----------------------------
CREATE TABLE IF NOT EXISTS `plugin_handle` (
`id` varchar(128) NOT NULL,
`plugin_id` varchar(128) NOT NULL COMMENT '插件id',
`field` varchar(100) NOT NULL COMMENT '字段',
`label` varchar(100) DEFAULT NULL COMMENT '标签',
`data_type` smallint(6) NOT NULL DEFAULT '1' COMMENT '数据类型 1 数字 2 字符串',
`date_created` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
`date_updated` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '更新时间',
PRIMARY KEY (`id`),
UNIQUE KEY `plugin_id_field` (`plugin_id`,`field`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE = utf8mb4_unicode_ci ROW_FORMAT = Dynamic;


/*plugin*/
INSERT IGNORE INTO `plugin` (`id`, `name`,`role`, `enabled`, `date_created`, `date_updated`) VALUES ('1', 'sign','0', '0', '2018-06-14 10:17:35', '2018-06-14 10:17:35');
INSERT IGNORE INTO `plugin` (`id`, `name`,`role`,`config`,`enabled`, `date_created`, `date_updated`) VALUES ('2', 'waf', '0','{"model":"black"}','0', '2018-06-23 10:26:30', '2018-06-13 15:43:10');
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
package org.dromara.soul.admin.controller;

import java.util.List;
import java.util.Objects;
import org.dromara.soul.admin.dto.PluginHandleDTO;
import org.dromara.soul.admin.page.CommonPager;
import org.dromara.soul.admin.page.PageParameter;
import org.dromara.soul.admin.query.PluginHandleQuery;
import org.dromara.soul.admin.result.SoulAdminResult;
import org.dromara.soul.admin.service.PluginHandleService;
import org.dromara.soul.admin.vo.PluginHandleVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
* this is a plugin handle controller.
* @author liangziqiang.
*/
@RestController
@RequestMapping("/plugin-handle")
public class PluginHandleController {
private final PluginHandleService pluginHandleService;

@Autowired(required = false)
public PluginHandleController(final PluginHandleService pluginHandleService) {
this.pluginHandleService = pluginHandleService;
}

/**
* query plugin handle by plugin id.
* @param pluginId plugin id.
* @param currentPage current page.
* @param pageSize page size
* @return {@linkplain SoulAdminResult}
*/
@GetMapping("")
public SoulAdminResult queryPluginHandles(final String pluginId, final Integer currentPage, final Integer pageSize) {
CommonPager<PluginHandleVO> commonPager = pluginHandleService.listByPage(new PluginHandleQuery(pluginId, new PageParameter(currentPage, pageSize)));
return SoulAdminResult.success("query plugin handle success", commonPager);
}

/**
* query plugin handle by plugin id.
* @param pluginId plugin id.
* @return {@linkplain SoulAdminResult}
*/
@GetMapping("/all/{pluginId}")
public SoulAdminResult queryAllPluginHandlesByPluginId(@PathVariable("pluginId") final String pluginId) {
List<PluginHandleVO> pluginHandleVOS = pluginHandleService.list(pluginId);
return SoulAdminResult.success("query plugin handle success", pluginHandleVOS);
}

/**
* detail rule.
*
* @param id rule id.
* @return {@linkplain SoulAdminResult}
*/
@GetMapping("/{id}")
public SoulAdminResult detailRule(@PathVariable("id") final String id) {
PluginHandleVO pluginHandleVO = pluginHandleService.findById(id);
return SoulAdminResult.success("detail plugin handle success", pluginHandleVO);
}

/**
* create plugin handle.
* @param pluginHandleDTO {@link PluginHandleDTO}
* @return {@link SoulAdminResult}
*/
@PostMapping("")
public SoulAdminResult createPluginHandle(@RequestBody final PluginHandleDTO pluginHandleDTO) {
Integer createCount = pluginHandleService.createOrUpdate(pluginHandleDTO);
return SoulAdminResult.success("add plugin handle success", createCount);
}

/**
* update plugin handle by id.
* @param id plugin handle id
* @param pluginHandleDTO {@linkplain PluginHandleDTO}
* @return {@linkplain SoulAdminResult}
*/
@PutMapping("/{id}")
public SoulAdminResult updatePluginHandle(@PathVariable("id") final String id, @RequestBody final PluginHandleDTO pluginHandleDTO) {
Objects.requireNonNull(pluginHandleDTO);
pluginHandleDTO.setId(id);
Integer updateCount = pluginHandleService.createOrUpdate(pluginHandleDTO);
return SoulAdminResult.success("update plugin handle success", updateCount);
}

/**
* batch delete some plugin handles by some id list.
* @param ids plugin handle id list.
* @return {@linkplain SoulAdminResult}
*/
@DeleteMapping("/batch")
public SoulAdminResult deletePluginHandles(@RequestBody final List<String> ids) {
Integer deleteCount = pluginHandleService.deletePluginHandles(ids);
return SoulAdminResult.success("delete plugin handle success", deleteCount);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package org.dromara.soul.admin.dto;

import java.io.Serializable;
import lombok.Data;

/**
* this plugin handle from web front.
* @author liangziqiang
*/
@Data
public class PluginHandleDTO implements Serializable {
/**
* primary key.
*/
private String id;

/**
* plugin id.
*/
private String pluginId;

/**
* the attribute name.
*/
private String field;

/**
* the attribute label.
*/
private String label;

/**
* the data type.
* 1 indicates number
* 2 indicates string
*/
private Integer dataType;

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
package org.dromara.soul.admin.entity;

import java.util.Objects;
import lombok.Data;
import org.apache.commons.lang3.StringUtils;
import org.dromara.soul.admin.dto.PluginHandleDTO;
import org.dromara.soul.common.utils.UUIDUtils;

/**
* plugin handle json definition.
* @author liangziqiang
*/
@Data
public class PluginHandleDO extends BaseDO {

/**
* plugin id.
*/
private String pluginId;

/**
* the attribute name.
*/
private String field;

/**
* the attribute label.
*/
private String label;

/**
* the data type.
* 1 indicates number
* 2 indicates string
*/
private Integer dataType;

/**
* build {@linkplain PluginHandleDO} instance.
* @param pluginHandleDTO {@linkplain PluginHandleDTO}
* @return {@linkplain PluginHandleDO}
*/
public static PluginHandleDO buildPluginHandleDO(final PluginHandleDTO pluginHandleDTO) {
if (Objects.isNull(pluginHandleDTO)) {
return null;
}

PluginHandleDO pluginHandleDO = new PluginHandleDO();
pluginHandleDO.setId(pluginHandleDTO.getId());
pluginHandleDO.setPluginId(pluginHandleDTO.getPluginId());
pluginHandleDO.setField(pluginHandleDTO.getField());
pluginHandleDO.setLabel(pluginHandleDTO.getLabel());
pluginHandleDO.setDataType(pluginHandleDTO.getDataType());
if (StringUtils.isEmpty(pluginHandleDTO.getId())) {
pluginHandleDO.setId(UUIDUtils.getInstance().generateShortUuid());
}
return pluginHandleDO;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
package org.dromara.soul.admin.mapper;

import java.util.List;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.dromara.soul.admin.entity.PluginHandleDO;
import org.dromara.soul.admin.query.PluginHandleQuery;

/**
* The interface Plugin handle mapper.
* @author liangziqiang
*/
@Mapper
public interface PluginHandleMapper {

/**
* Select plugin handle by id.
* @param id the id.
* @return the plugin handle do.
*/
PluginHandleDO selectById(@Param("id") String id);

/**
* find plugin handle do list by plugin id.
* @param pluginId the pluginId
* @return the list
*/
List<PluginHandleDO> findByPluginId(@Param("pluginId") String pluginId);

/**
* insert plugin handle.
* @param record {@link PluginHandleDO}
* @return affected rows
*/
int insert(PluginHandleDO record);

/**
* insert selective plugin handle.
* @param record {@link PluginHandleDO}
* @return affected rows.
*/
int insertSelective(PluginHandleDO record);

/**
* count plugin handle by query.
* @param pluginHandleQuery {@linkplain PluginHandleQuery}
* @return the count
*/
int countByQuery(PluginHandleQuery pluginHandleQuery);

/**
* select plugin handle list by query.
* @param pluginHandleQuery {@linkplain PluginHandleQuery}
* @return the plugin handle list
*/
List<PluginHandleDO> selectByQuery(PluginHandleQuery pluginHandleQuery);

/**
* update some selective columns in plugin_handle.
* @param record {@linkplain PluginHandleDO}
* @return affected rows
*/
int updateByPrimaryKeySelective(PluginHandleDO record);

/**
* update plugin handle by primary key.
* @param record {@linkplain PluginHandleDO}
* @return affected rows.
*/
int updateByPrimaryKey(PluginHandleDO record);

/**
* delete string id.
* @param id plugin handle id
* @return affected rows
*/
int delete(String id);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package org.dromara.soul.admin.query;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.dromara.soul.admin.page.PageParameter;

/**
* this is plugin handle query.
* @author liangziqiang
*/
@Data
@AllArgsConstructor
@NoArgsConstructor
public class PluginHandleQuery {
/**
* plugin id.
*/
private String pluginId;

/**
* page parameter.
*/
private PageParameter pageParameter;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
package org.dromara.soul.admin.service;

import java.util.List;
import org.dromara.soul.admin.dto.PluginHandleDTO;
import org.dromara.soul.admin.page.CommonPager;
import org.dromara.soul.admin.query.PluginHandleQuery;
import org.dromara.soul.admin.vo.PluginHandleVO;

/**
* this is plugin handle service.
* @author liangziqiang
*/
public interface PluginHandleService {
/**
* find page of rule by query.
* @param pluginHandleQuery {@linkplain PluginHandleQuery}
* @return {@link CommonPager}
*/
CommonPager<PluginHandleVO> listByPage(PluginHandleQuery pluginHandleQuery);

/**
* create or update plugin handle.
* @param pluginHandleDTO {@linkplain PluginHandleDTO}
* @return affected rows
*/
Integer createOrUpdate(PluginHandleDTO pluginHandleDTO);

/**
* delete plugin handles.
* @param ids ids to delete
* @return The number of rows deleted
*/
Integer deletePluginHandles(List<String> ids);

/**
* find plugin handle by id.
* @param id plugin handle id.
* @return {@linkplain PluginHandleVO}
*/
PluginHandleVO findById(String id);

/**
* find plugin handle list by plugin id.
* @param pluginId the plugin id.
* @return plugin handle list.
*/
List<PluginHandleVO> list(String pluginId);
}
Loading

0 comments on commit 14a888b

Please sign in to comment.