class CodeController {

    @RequestMapping(value = "/files")
    public ServiceResult<List<W2uiElement>> getFiles(@RequestParam(value = "projectId", defaultValue = "") String projectId,
                                                     @RequestParam(value = "name", defaultValue = "") String name) {

        if (StringUtils.isBlank(projectId) || StringUtils.isBlank(name)) {
            return ServiceResult.fail("projectId 或 name 为空!!!");
        }
        List<W2uiElement> files = new ArrayList<>();

        File currentProjectDir = new File(new File(consts.codeConsoleilePath, projectId), CodeGenConsts.JAVA);
        if (currentProjectDir.exists()) {
            File currentFile;
            if (StringUtils.isBlank(name)) {
                currentFile = currentProjectDir;
            } else {
                currentFile = new File(currentProjectDir, name);
            }
            for (File f : currentFile.listFiles()) {
                W2uiElement element = new W2uiElement();
                if (null == name || name.isEmpty()) {
                    element.setId(String.format("%s_%d", projectId, files.size()));
                } else {
                    element.setId(String.format("%s_%s_%d", projectId, name.replace("\\", ""), files.size()));
                }
                if (null == name || name.isEmpty()) {
                    element.setData(f.getName());
                } else {
                    element.setData(name + File.separator + f.getName());
                }
                element.setText(f.getName());
                element.setChildren(f.isDirectory());
                if (element.isChildren()) {
                    element.setType("folder");
                } else {
                    element.setType("file");
                }
                files.add(element);
            }
        }
        return ServiceResult.success(files);
    }

}