From df321b0e7b7859be9c74cdd682549ee843f18b30 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?=E8=B5=B5=E5=95=B8=E9=9D=9E?= <13281114856@qq.com>
Date: Mon, 30 May 2022 13:59:19 +0800
Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E9=83=A8=E5=88=86=E7=94=9F?=
 =?UTF-8?q?=E6=88=90=E4=BB=A3=E7=A0=81=E9=80=BB=E8=BE=91?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

---
 .../resources/template/java/webBody.java.ftl  | 134 ++++++++++++++++++
 1 file changed, 134 insertions(+)
 create mode 100644 appbuild-manager/src/main/resources/template/java/webBody.java.ftl

diff --git a/appbuild-manager/src/main/resources/template/java/webBody.java.ftl b/appbuild-manager/src/main/resources/template/java/webBody.java.ftl
new file mode 100644
index 0000000..d48a1b7
--- /dev/null
+++ b/appbuild-manager/src/main/resources/template/java/webBody.java.ftl
@@ -0,0 +1,134 @@
+package ${packageName}.web;
+import com.mortals.framework.web.BaseCRUDJsonBodyMappingController;
+import com.mortals.xhx.base.system.param.service.ParamService;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RestController;
+import org.springframework.web.bind.annotation.*;
+import com.mortals.framework.model.Context;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+import com.mortals.framework.web.BaseCRUDJsonBodyMappingController;
+import ${packageName}.model.${ClassName}Entity;
+import ${packageName}.model.${ClassName}Query;
+import ${packageName}.service.${ClassName}Service;
+<#if table.tplCategory=="tree">
+import ${packageName}.model.${ClassName}TreeSelect;
+</#if>
+import org.apache.commons.lang3.ArrayUtils;
+import com.mortals.framework.util.StringUtils;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.stream.Collectors;
+import com.alibaba.fastjson.JSONObject;
+import java.util.Arrays;
+import org.springframework.web.bind.annotation.*;
+import org.springframework.web.multipart.MultipartFile;
+import static com.mortals.framework.ap.SysConstains.*;
+/**
+*
+* ${functionName}
+*
+* @author ${author}
+* @date ${datetime}
+*/
+@RestController
+@RequestMapping("${RequestMapping}")
+public class ${ClassName}Controller extends BaseCRUDJsonBodyMappingController<${ClassName}Service,${ClassName}Entity,${pkColumn.javaType}> {
+
+    @Autowired
+    private ParamService paramService;
+
+    public ${ClassName}Controller(){
+        super.setFormClass(${ClassName}Form.class);
+        super.setModuleDesc( "${functionName}");
+    }
+
+    @Override
+    protected void init(Map<String, Object> model, Context context) {
+        <#list columns as column>
+            <#if column.columnType?contains("tinyint") ||column.htmlType==3||column.htmlType==5>
+        this.addDict(model, "${column.javaField}", paramService.getParamBySecondOrganize("${ClassName}","${column.javaField}"));
+            </#if>
+        </#list>
+        super.init(model, context);
+    }
+
+<#if table.tplCategory=="tree">
+    @PostMapping("list/exclude")
+    public String excludeList(${ClassName}Form form) {
+        Map<String, Object> model = new HashMap<>();
+        JSONObject ret = new JSONObject();
+        String busiDesc = "鏌ヨ" + this.getModuleDesc();
+        Long id = form.getId()[0];
+        int code=VALUE_RESULT_SUCCESS;
+        try {
+            List<${ClassName}Entity> collect = this.service.find(new ${ClassName}Query()).stream().map(item -> {
+                if (item.getId().intValue() == id || ArrayUtils.contains(StringUtils.split(item.getAncestors(), ","), id + "")) {
+                    return null;
+                }
+                return item;
+            }).filter(f -> f != null).collect(Collectors.toList());
+            model.put("result", collect);
+            recordSysLog(request, busiDesc + " 銆愭垚鍔熴€�");
+        } catch (Exception e) {
+            code = VALUE_RESULT_FAILURE;
+            this.doException(request, busiDesc, model, e);
+        }
+        ret.put(KEY_RESULT_DATA, model);
+        ret.put(KEY_RESULT_CODE, code);
+        return ret.toJSONString();
+    }
+
+
+    /**
+     * 鑾峰彇绔欑偣涓嬫媺鏍戝垪琛�
+     */
+    @PostMapping("treeselect")
+    public String treeselect(${ClassName}Form form) {
+        Map<String, Object> model = new HashMap<>();
+        JSONObject ret = new JSONObject();
+        String busiDesc = "鏌ヨ" + this.getModuleDesc();
+        int code=VALUE_RESULT_SUCCESS;
+        try {
+            List<${ClassName}Entity> list = this.service.find(new ${ClassName}Query());
+            List<${ClassName}TreeSelect> treeSelects = this.service.build${ClassName}TreeSelect(list);
+             model.put("result", treeSelects);
+            recordSysLog(request, busiDesc + " 銆愭垚鍔熴€�");
+        } catch (Exception e) {
+            code = VALUE_RESULT_FAILURE;
+            this.doException(request, busiDesc, model, e);
+        }
+        ret.put(KEY_RESULT_DATA, model);
+        ret.put(KEY_RESULT_CODE, code);
+        return ret.toJSONString();
+    }
+
+
+    /**
+    * 鏍规嵁parentId鏌ヨ瀛愪俊鎭�
+    */
+    @GetMapping(value = "getListByParentId")
+    public String getListByParentId(String parentId) {
+        JSONObject ret = new JSONObject();
+        Map<String, Object> model = new HashMap<>();
+        String busiDesc = "鏌ヨ" + this.getModuleDesc()+"瀛愯妭鐐�";
+        try {
+            List<${ClassName}TreeSelect> treeList = this.service.getListByParentId(parentId, getContext());
+            model.put(RESULT_KEY,treeList);
+            ret.put(KEY_RESULT_CODE, VALUE_RESULT_SUCCESS);
+            ret.put(KEY_RESULT_DATA, model);
+            recordSysLog(request, busiDesc+"銆愭垚鍔熴€�");
+        } catch (Exception e) {
+            log.error("鏍规嵁parentId鏌ヨ瀛愪俊鎭敊璇�", e);
+            this.doException(request, busiDesc, model, e);
+            ret.put(KEY_RESULT_CODE, VALUE_RESULT_FAILURE);
+            ret.put(KEY_RESULT_MSG, e.getMessage());
+        }
+        return ret.toJSONString();
+    }
+
+</#if>
+
+}
\ No newline at end of file
-- 
2.24.3