class TransController {

    @RequestMapping(value = "/toDas", method = RequestMethod.POST)
    public ServiceResult<String> convert(@RequestBody TransRequest transRequest, @CurrentUser LoginUser user, Errors errors) {

        try {
            Configuration configuration = createConfiguration();

            InputStream inputStream = new ByteArrayInputStream(transRequest.getXmlContent().getBytes(StandardCharsets.UTF_8));
            XMLMapperBuilder mapperParser = new XMLMapperBuilder(inputStream, configuration, "any.xml", configuration.getSqlFragments());
            mapperParser.parse();

            Collection<MappedStatement> statements = uniqueStatements(mapperParser.getConfiguration().getMappedStatements());
            List<Statement> convertedStatements = newArrayList();
            VelocityContext context = new VelocityContext();

            Set<String> importResultMaps = importResultMaps(configuration);
            context.put("importResultMaps", importResultMaps);
            context.put("classComments", classComments(importResultMaps));
            context.put("className", createClassName(mapperParser));
            context.put("statements", convertedStatements);

            for(MappedStatement statement : statements) {
                if (statement.getSqlCommandType() == SELECT || statement.getSqlCommandType() == INSERT
                        || statement.getSqlCommandType() == UPDATE || statement.getSqlCommandType() == DELETE) {
                    try{
                        SqlSource sqlSource = statement.getSqlSource();
                        ArrayList<Seg> segs = new ArrayList<>();
                        LinkedHashMap<String, String> params = newLinkedHashMap();

                        Class parameterType = statement.getParameterMap().getType();
                        StringBuilder comments = new StringBuilder();
                        if(statement.isUseCache()) {
                            //comments.append(SEP).append("不支持useCache属性");
                        }
                        if(sqlSource instanceof RawSqlSource) {
                            List<ParameterMapping> parameterMappings = get(get(sqlSource, "sqlSource"), "parameterMappings");
                            LinkedHashMap<String, String> parsedParams = getParams(parameterMappings);

                            StaticTextSqlNode node = new StaticTextSqlNode(get(get(sqlSource, "sqlSource"), "sql"));
                            walkNodes(node, configuration, statement, segs, new AtomicInteger(0), params, newLinkedList(), parsedParams, parameterType, comments, Sets.newHashSet());
                        } else {
                            walkNodes(get(sqlSource, "rootSqlNode"), configuration, statement, segs, new AtomicInteger(0), params, newLinkedList(), newLinkedHashMap(), parameterType, comments, Sets.newHashSet());
                        }

                        String resultType = getResultType(statement).getSimpleName();

                        if(parameterType != null){
                            params.clear();
                            params.put("p" + parameterType.getSimpleName(),  parameterType.getName());
                        }

                        Class resultClass = getResultType(statement);
                        if(statement.getSqlCommandType() == SELECT ){
                            segs.add(new Seg("sqlBuilder." + getIntoType(resultClass) + ";"));
                        }
                        Statement converted = new Statement()
                                .setId(statement.getId())
                                .setMethodBody(join(segs))
                                .setMethodType(statement.getSqlCommandType() == SELECT ? "query" : "update")
                                .setResultType(statement.getSqlCommandType() == SELECT && !isPrimitiveType(resultClass) ? "List<" + resultType + ">" : resultType)
                                .setParams(params)
                                .setComments(comments.toString());

                        convertedStatements.add(converted);
                    }catch (Exception e){
                        Statement converted = new Statement()
                                .setId(statement.getId())
                                .setFail(true);
                        convertedStatements.add(converted);
                        e.printStackTrace();
                    }
                }
            }

            String finalResult = mergeTemplate(context);
            String formattedSource = finalResult;
            try {
                formattedSource = new Formatter().formatSource(finalResult);
            } catch (FormatterException fe) {
                fe.printStackTrace();
            }
            return ServiceResult.success(formattedSource);
        }catch (Exception e){
            e.printStackTrace();
            return ServiceResult.fail(StringUtil.getMessage(e));
        }
    }

}