init
This commit is contained in:
@@ -0,0 +1,79 @@
|
||||
package com.cool.modules.plugin.controller.admin;
|
||||
|
||||
import cn.hutool.core.convert.Convert;
|
||||
import cn.hutool.core.util.ObjUtil;
|
||||
import cn.hutool.json.JSONObject;
|
||||
import cn.hutool.json.JSONUtil;
|
||||
import com.cool.core.annotation.CoolRestController;
|
||||
import com.cool.core.annotation.IgnoreRecycleData;
|
||||
import com.cool.core.base.BaseController;
|
||||
import com.cool.core.plugin.service.CoolPluginService;
|
||||
import com.cool.core.request.R;
|
||||
import com.cool.modules.plugin.entity.PluginInfoEntity;
|
||||
import com.cool.modules.plugin.service.PluginInfoService;
|
||||
import com.mybatisflex.core.query.QueryWrapper;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import io.swagger.v3.oas.annotations.Parameter;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import jakarta.servlet.http.HttpServletRequest;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.http.MediaType;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestAttribute;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import static com.cool.modules.plugin.entity.table.PluginInfoEntityTableDef.PLUGIN_INFO_ENTITY;
|
||||
|
||||
@Tag(name = "插件信息", description = "插件信息")
|
||||
@CoolRestController(api = {"add", "delete", "update", "page", "list", "info"})
|
||||
@RequiredArgsConstructor
|
||||
public class AdminPluginInfoController extends BaseController<PluginInfoService, PluginInfoEntity> {
|
||||
|
||||
final private CoolPluginService coolPluginService;
|
||||
|
||||
@Override
|
||||
protected void init(HttpServletRequest request, JSONObject requestParams) {
|
||||
|
||||
setPageOption(createOp().queryWrapper(
|
||||
QueryWrapper.create().orderBy(PLUGIN_INFO_ENTITY.UPDATE_TIME, false))
|
||||
.select(PLUGIN_INFO_ENTITY.DEFAULT_COLUMNS));
|
||||
}
|
||||
|
||||
@Override
|
||||
@Operation(summary = "修改", description = "根据ID修改")
|
||||
@PostMapping("/update")
|
||||
protected R update(@RequestBody PluginInfoEntity t,
|
||||
@RequestAttribute() JSONObject requestParams) {
|
||||
if (ObjUtil.isNotEmpty(t.getConfig())) {
|
||||
t.setConfig(JSONUtil.parseObj(t.getConfig()));
|
||||
} else {
|
||||
t.setConfig(new HashMap<>());
|
||||
}
|
||||
coolPluginService.updatePlugin(t);
|
||||
return R.ok();
|
||||
}
|
||||
|
||||
@Operation(summary = "安装插件")
|
||||
@PostMapping(value = "/install", consumes = MediaType.MULTIPART_FORM_DATA_VALUE)
|
||||
public R install(
|
||||
@RequestParam(value = "files") @Parameter(description = "文件") MultipartFile[] files,
|
||||
@RequestParam(value = "force") @Parameter(description = "是否强制安装") boolean force) {
|
||||
coolPluginService.install(files[0], force);
|
||||
return R.ok();
|
||||
}
|
||||
|
||||
@Override
|
||||
@Operation(summary = "卸载插件")
|
||||
@PostMapping("/delete")
|
||||
@IgnoreRecycleData()
|
||||
public R delete(HttpServletRequest request, @RequestBody Map<String, Object> params,
|
||||
@RequestAttribute() JSONObject requestParams) {
|
||||
coolPluginService.uninstall(Convert.toLongArray(getIds(params))[0]);
|
||||
return R.ok();
|
||||
}
|
||||
}
|
@@ -0,0 +1,65 @@
|
||||
package com.cool.modules.plugin.entity;
|
||||
|
||||
import com.cool.core.base.BaseEntity;
|
||||
import com.cool.core.config.PluginJson;
|
||||
import com.cool.core.mybatis.handler.Fastjson2TypeHandler;
|
||||
import com.cool.core.mybatis.handler.JacksonTypeHandler;
|
||||
import com.mybatisflex.annotation.Column;
|
||||
import com.mybatisflex.annotation.Table;
|
||||
import com.tangzc.mybatisflex.autotable.annotation.ColumnDefine;
|
||||
import com.tangzc.mybatisflex.autotable.annotation.UniIndex;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
import org.dromara.autotable.annotation.Ignore;
|
||||
import org.dromara.autotable.annotation.Index;
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
@Table(value = "plugin_info", comment = "插件信息")
|
||||
public class PluginInfoEntity extends BaseEntity<PluginInfoEntity> {
|
||||
|
||||
@ColumnDefine(comment = "名称")
|
||||
private String name;
|
||||
|
||||
@ColumnDefine(comment = "简介")
|
||||
private String description;
|
||||
|
||||
@UniIndex
|
||||
@ColumnDefine(comment = "实例对象")
|
||||
private String key;
|
||||
|
||||
@Index
|
||||
@ColumnDefine(comment = "Hook", length = 50)
|
||||
private String hook;
|
||||
|
||||
@ColumnDefine(comment = "描述", type = "text")
|
||||
private String readme;
|
||||
|
||||
@ColumnDefine(comment = "版本")
|
||||
private String version;
|
||||
|
||||
@ColumnDefine(comment = "Logo(base64)", type = "text", notNull = true)
|
||||
private String logo;
|
||||
|
||||
@ColumnDefine(comment = "作者")
|
||||
private String author;
|
||||
|
||||
@ColumnDefine(comment = "状态 0-禁用 1-启用", defaultValue = "1")
|
||||
private Integer status;
|
||||
|
||||
@ColumnDefine(comment = "插件的plugin.json", type = "json", notNull = true)
|
||||
@Column(typeHandler = Fastjson2TypeHandler.class)
|
||||
private PluginJson pluginJson;
|
||||
|
||||
@ColumnDefine(comment = "配置", type = "json")
|
||||
@Column(typeHandler = JacksonTypeHandler.class)
|
||||
private Object config;
|
||||
|
||||
@Ignore
|
||||
@Column(ignore = true)
|
||||
public String keyName;
|
||||
|
||||
public String getKeyName() {
|
||||
return key;
|
||||
}
|
||||
}
|
@@ -0,0 +1,8 @@
|
||||
package com.cool.modules.plugin.mapper;
|
||||
|
||||
import com.cool.modules.plugin.entity.PluginInfoEntity;
|
||||
import com.mybatisflex.core.BaseMapper;
|
||||
|
||||
public interface PluginInfoMapper extends BaseMapper<PluginInfoEntity> {
|
||||
|
||||
}
|
@@ -0,0 +1,12 @@
|
||||
package com.cool.modules.plugin.service;
|
||||
|
||||
import com.cool.core.base.BaseService;
|
||||
import com.cool.modules.plugin.entity.PluginInfoEntity;
|
||||
|
||||
public interface PluginInfoService extends BaseService<PluginInfoEntity> {
|
||||
PluginInfoEntity getByKey(String key);
|
||||
|
||||
PluginInfoEntity getPluginInfoEntityByHook(String hook);
|
||||
|
||||
PluginInfoEntity getPluginInfoEntityById(Long id);
|
||||
}
|
@@ -0,0 +1,54 @@
|
||||
package com.cool.modules.plugin.service.impl;
|
||||
|
||||
import com.cool.core.base.BaseServiceImpl;
|
||||
import com.cool.modules.plugin.entity.PluginInfoEntity;
|
||||
import com.cool.modules.plugin.mapper.PluginInfoMapper;
|
||||
import com.cool.modules.plugin.service.PluginInfoService;
|
||||
import com.mybatisflex.core.query.QueryWrapper;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import static com.cool.modules.plugin.entity.table.PluginInfoEntityTableDef.PLUGIN_INFO_ENTITY;
|
||||
|
||||
/**
|
||||
* 插件信息服务类
|
||||
*/
|
||||
@Service
|
||||
public class PluginInfoServiceImpl extends BaseServiceImpl<PluginInfoMapper, PluginInfoEntity>
|
||||
implements PluginInfoService {
|
||||
|
||||
/**
|
||||
* 通过key获取插件信息
|
||||
*/
|
||||
@Override
|
||||
public PluginInfoEntity getByKey(String key) {
|
||||
QueryWrapper queryWrapper = QueryWrapper.create();
|
||||
queryWrapper.and(PLUGIN_INFO_ENTITY.KEY.eq(key));
|
||||
return getOne(queryWrapper);
|
||||
}
|
||||
|
||||
/**
|
||||
* 通过hook获取插件信息
|
||||
*/
|
||||
@Override
|
||||
public PluginInfoEntity getPluginInfoEntityByHook(String hook) {
|
||||
QueryWrapper queryWrapper = getPluginInfoEntityQueryWrapper().and(PLUGIN_INFO_ENTITY.HOOK.eq(hook))
|
||||
.and(PLUGIN_INFO_ENTITY.STATUS.eq(1)).limit(1);
|
||||
return getOne(queryWrapper);
|
||||
}
|
||||
|
||||
/**
|
||||
* 通过id获取插件信息
|
||||
*/
|
||||
@Override
|
||||
public PluginInfoEntity getPluginInfoEntityById(Long id) {
|
||||
QueryWrapper queryWrapper = getPluginInfoEntityQueryWrapper().and(PLUGIN_INFO_ENTITY.ID.eq(id));
|
||||
return getOne(queryWrapper);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取查询对象
|
||||
*/
|
||||
private QueryWrapper getPluginInfoEntityQueryWrapper() {
|
||||
return QueryWrapper.create();
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user