feat: 增加修改配置文件的命令

dev
huangfeng 11 months ago
parent 6e95543cfe
commit 35901cc8eb

@ -47,7 +47,7 @@ public class CmdController extends BaseController {
list.add(new ActionModel(12, "del_file", "删除文件")); list.add(new ActionModel(12, "del_file", "删除文件"));
list.add(new ActionModel(13, "pull_files", "拉取文件")); list.add(new ActionModel(13, "pull_files", "拉取文件"));
list.add(new ActionModel(14, "push_file", "推送文件")); list.add(new ActionModel(14, "push_file", "推送文件"));
// list.add(new ActionModel(15, "dl_file", "推送大文件")); list.add(new ActionModel(15, "upd_cfg", "修改配置文件"));
return ResponseReult.success(list); return ResponseReult.success(list);
} }

@ -2,6 +2,7 @@ package com.shxy.xymanager_common.model;
import lombok.Data; import lombok.Data;
import java.util.HashMap;
import java.util.List; import java.util.List;
@Data @Data
@ -29,4 +30,6 @@ public class CmdModel {
private String path; private String path;
private String content; private String content;
private List<String> paths; private List<String> paths;
private String packageName;
private List<HashMap<String, Object>> configs;
} }

@ -241,6 +241,9 @@ public class CmdServiceImpl implements CmdService {
case "upgrade": case "upgrade":
this.upgrade(model); this.upgrade(model);
break; break;
case "upd_cfg":
this.updateCfg(model);
break;
case "dl_file": case "dl_file":
this.dlFile(model); this.dlFile(model);
break; break;
@ -799,4 +802,41 @@ public class CmdServiceImpl implements CmdService {
cmdsMapper.insert(cmd); cmdsMapper.insert(cmd);
} }
} }
private void updateCfg(CmdModel model) {
if (CollectionUtils.isEmpty(model.getTermIds())) {
throw new ApiException("termIds不能为空");
} else if (StringUtils.isBlank(model.getPath())) {
throw new ApiException("path不能为空");
} else if (StringUtils.isBlank(model.getPackageName())) {
throw new ApiException("packageName不能为空");
} else if (StringUtils.isBlank(model.getFn())) {
throw new ApiException("fn不能为空");
} else if (model.getConfigs() == null) {
throw new ApiException("configs不能为空");
}
String name = "upd_cfg";
for (Integer termId : model.getTermIds()) {
MntnCmdsExample example = new MntnCmdsExample();
MntnCmdsExample.Criteria criteria = example.createCriteria();
criteria.andTermIdEqualTo(termId);
criteria.andNameEqualTo(name);
cmdsMapper.deleteByExample(example);
HashMap<String, Object> map = new HashMap<>();
map.put("path", model.getPath());
map.put("packageName", model.getPackageName());
map.put("fileName", model.getFn());
map.put("configs", model.getConfigs());
String json = JSONUtil.object2Json(map);
MntnCmds cmd = new MntnCmds();
cmd.setTermId(termId);
cmd.setName(name);
cmd.setCmd(json);
cmd.setCreateTime(new Date());
cmdsMapper.insert(cmd);
}
}
} }

Loading…
Cancel
Save