cy
2022-06-21 129904537f66509f97b285e7eb4f42b3dc349dd0
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
package ${cPackageName};
<#assign fullpath=cPackageName?replace(".","/")/>
<#assign path=fullpath?substring(fullpath?index_of("/business/"))/>
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.ArrayList;
 
import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
 
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.servlet.ModelAndView;
 
import cn.ksource.core.page.PageInfo;
import cn.ksource.core.util.ParamsMapUtil;
import cn.ksource.core.util.StringUtil;
import cn.ksource.core.web.SysInfo;
import cn.ksource.core.web.WebUtil;
import cn.ksource.web.service.DataDictionaryService;
import cn.ksource.web.Constants;
import cn.ksource.web.facade.${className?uncap_first}.${className}Facade;
 
@SuppressWarnings("rawtypes")
@Controller
@RequestMapping("${path}")
public class ${className}Controller {
    
    @Resource
    private ${className}Facade ${className?uncap_first}Facade;
    @Resource
    private DataDictionaryService dataDictionaryService;
    
    private void setModel(Model model){
        <#if options??&&options?size gt 0>
        <#list options as item>
        <#if item.field_type=="dic"||item.field_type=="constants">
            List<Map> ${item.SelSc}List = new ArrayList<Map>();
            <#if item.field_type=="constants">
                for(Integer key:Constants.${item.SelKey}.keySet()){
                    Map map = new HashMap();
                    map.put("datakey", key);
                    map.put("datavalue", Constants.get${item.SelKey}(key));
                    ${item.SelSc}List.add(map);
                }
            <#elseif item.field_type=="dic">    
                ${item.SelSc}List = dataDictionaryService.getDataDictionaryByCategoryKey(Constants.${item.SelKey});
            </#if>
            model.addAttribute("${item.SelSc}List",${item.SelSc}List);
        </#if>
        </#list>
        </#if>
    }
    /**
     * 新增,编辑
     * @return
     * @author chenlong
     */
    @RequestMapping(value="edit${className}.html",method=RequestMethod.GET)
    public String edit${className}(Model model,HttpServletRequest request){
        setModel(model);
        String id = request.getParameter("id");
        if(StringUtil.isNotBlank(id)){
            model.addAttribute("info",  ${className?uncap_first}Facade.get${className}ById(id));
        }else{
            model.addAttribute("info", new HashMap());
        }
        return "${path}/edit${className}";
    }
    
    @RequestMapping(value="edit${className}.html",method=RequestMethod.POST)
    public ModelAndView doEdit${className}(Model model,HttpServletRequest request){
        Map<String,String> params = ParamsMapUtil.getParameterMap(request);
        ${className?uncap_first}Facade.save${className}(params);
        return WebUtil.sysInfoPage(request, "操作成功",
                "window.top.hideDialog('0');window.top.query();",
                SysInfo.Success,"");
    }
    
    /**
     * 列表
     * @param model
     * @param request
     * @param response
     * @return
     * @author liusen
     */
    @RequestMapping("${className?uncap_first}List.html")
    public String ${className?uncap_first}List(Model model,HttpServletRequest request,HttpServletResponse response){
        return "${path}/${className?uncap_first}List";
    }
    
    @RequestMapping("${className?uncap_first}ListData.html")
    private String ${className?uncap_first}ListData(Model model,HttpServletRequest request,PageInfo pageInfo){
        Map<String,String> param = ParamsMapUtil.getParameterMap(request);
        PageInfo page = ${className?uncap_first}Facade.get${className}ListData(pageInfo, param);
        model.addAttribute("page", page);
        return "${path}/${className?uncap_first}ListData";
    }
    
    @RequestMapping("${className?uncap_first}ListCount.html")
    public void ${className?uncap_first}ListCount(HttpServletRequest request,HttpServletResponse response) {    
        Map<String,String> param=ParamsMapUtil.getParameterMap(request);    
        Integer count=${className?uncap_first}Facade.get${className}ListCount(param);
        WebUtil.write(response, String.valueOf(count));    
    }
    
    /**
     * 删除
     * @param request
     * @param response
     * @author chenlong
     */
    @RequestMapping("del${className}.html")
    public void del${className}(HttpServletRequest request,HttpServletResponse response){
        String id = request.getParameter("id");
        ${className?uncap_first}Facade.del${className}ById(id);
        WebUtil.write(response, "1");    
    }
    
}