1
+ package net .liuxuan .SprKi .controller .admin .labthink ;
2
+
3
+ import net .liuxuan .SprKi .entity .DTO .BaseDTO ;
4
+ import net .liuxuan .SprKi .entity .security .LogActionType ;
5
+ import net .liuxuan .SprKi .entity .CMSComment ;
6
+ import net .liuxuan .SprKi .service .CMSCommentService ;
7
+ import net .liuxuan .spring .Helper .ResponseHelper ;
8
+ import net .liuxuan .spring .Helper .SecurityLogHelper ;
9
+ import org .slf4j .Logger ;
10
+ import org .slf4j .LoggerFactory ;
11
+ import org .springframework .beans .factory .annotation .Autowired ;
12
+ import org .springframework .security .access .prepost .PreAuthorize ;
13
+ import org .springframework .stereotype .Controller ;
14
+ import org .springframework .web .bind .annotation .ModelAttribute ;
15
+ import org .springframework .web .bind .annotation .RequestMapping ;
16
+
17
+ import javax .servlet .http .HttpServletRequest ;
18
+ import javax .servlet .http .HttpServletResponse ;
19
+ import java .io .IOException ;
20
+ import java .util .HashMap ;
21
+ import java .util .List ;
22
+ import java .util .Map ;
23
+
24
+ /**
25
+ * Copyright (c) 2010-2016. by Liuxuan All rights reserved. <br/>
26
+ * ***************************************************************************
27
+ * 源文件名: net.liuxuan.SprKi.controller.admin.labthink.CMSCommentRepository
28
+ * 功能:
29
+ * 版本: @version 1.0
30
+ * 编制日期: 2017/06/21 14:36
31
+ * 修改历史: (主要历史变动原因及说明)
32
+ * YYYY-MM-DD | Author | Change Description
33
+ * 2017-06-21 | Moses | Created
34
+ */
35
+
36
+ @ Controller
37
+ @ RequestMapping ("/admin" )
38
+ public class CMSCommentManagementController {
39
+ private static Logger log = LoggerFactory .getLogger (CMSCommentManagementController .class );
40
+
41
+ @ Autowired
42
+ CMSCommentService cMSCommentService ;
43
+
44
+ @ RequestMapping ("cMSCommentManage" )
45
+ @ PreAuthorize ("hasRole('ROLE_ADMIN')" )
46
+ public String getPages (Map <String , Object > model ) {
47
+
48
+ return "admin/" + "cMSCommentManage" + " :: middle" ;
49
+
50
+ }
51
+
52
+ @ RequestMapping ("cMSComment" )
53
+ public String cMSCommentManage (@ ModelAttribute ("dto" ) BaseDTO dto , HttpServletRequest request ,
54
+ HttpServletResponse response , Map <String , Object > model ) throws IOException {
55
+ log .info ("===cMSCommentManage logged ,the _dto value is : {}" , dto .toString ());
56
+
57
+ switch (dto .action ) {
58
+ case "edit" :
59
+ CMSComment cMSComment ;
60
+ Long id = dto .getStr2LongID ();
61
+
62
+ cMSComment = cMSCommentService .findCMSCommentById (id );
63
+ if (cMSComment != null ) {
64
+ } else {
65
+ throw new IOException ("Got Wrong ID" );
66
+ }
67
+ model .put ("cMSComment" , cMSComment );
68
+ return "admin/snipplets/div_cMSComment :: cMSCommentedit" ;
69
+ default :
70
+ return "redirect:/admin/cMSComment_ajax" ;
71
+ // break;
72
+ }
73
+ }
74
+
75
+
76
+ @ RequestMapping ("cMSComment_ajax" )
77
+ // @ResponseBody
78
+ public void cMSCommentManageAjax (@ ModelAttribute ("dto" ) BaseDTO _dto , CMSComment _cMSComment , HttpServletRequest request ,
79
+ HttpServletResponse response ) throws IOException {
80
+ // response.setContentType("application/json");
81
+ Map <String , Object > rtnData = new HashMap <String , Object >();
82
+ log .info ("===cMSCommentManageAjax logged ,the value is : {}" , _dto .toString ());
83
+ Long id = _dto .getStr2LongID ();
84
+
85
+ // response.setContentType("application/json");
86
+ // ObjectMapper mapper = new ObjectMapper();
87
+ // mapper.configure(SerializationFeature.INDENT_OUTPUT, true);
88
+ switch (_dto .action ) {
89
+ case "add" :
90
+ String cMSCommentName = request .getParameter ("cMSCommentName" );
91
+ String cMSCommentNameCN = request .getParameter ("cMSCommentNameCN" );
92
+ String comment = request .getParameter ("comment" );
93
+ // boolean cMSCommentExists = cMSCommentService.checkCMSCommentExists(cMSCommentName);
94
+ // if (cMSCommentExists) {
95
+ // log.info("===cMSCommentManageAjax logged ,添加CMSComment已存在 : {}");
96
+ // rtnData.put("error", "ERROR_CMSCommentExists");
97
+ // rtnData.put("status", "fail");
98
+ // rtnData.put("msg", "添加CMSComment已存在");
99
+ // } else {
100
+ rtnData .put ("status" , "success" );
101
+ rtnData .put ("msg" , "成功添加CMSComment" );
102
+ SecurityLogHelper .LogHIGHRIGHT (request , LogActionType .ADMIN_CREATE , _cMSComment , "添加角色" , "" );
103
+ cMSCommentService .saveCMSComment (_cMSComment );
104
+ // }
105
+ break ;
106
+ case "delete" :
107
+ SecurityLogHelper .LogHIGHRIGHT (request , LogActionType .ADMIN_DELETE , _dto , "删除角色" , "" );
108
+ boolean b = cMSCommentService .deleteCMSCommentById (id );
109
+ if (b ) {
110
+ rtnData .put ("status" , "success" );
111
+ rtnData .put ("msg" , "成功删除CMSComment" );
112
+ } else {
113
+ rtnData .put ("error" , "ERROR_CMSCommentNotExists" );
114
+ rtnData .put ("status" , "fail" );
115
+ rtnData .put ("msg" , "CMSComment不存在,删除失败" );
116
+ }
117
+ break ;
118
+ case "update" :
119
+ cMSCommentService .saveCMSComment (_cMSComment );
120
+ SecurityLogHelper .LogHIGHRIGHT (request , LogActionType .ADMIN_UPDATE , _cMSComment , "更新CMSComment" , "" );
121
+ rtnData .put ("success1" , "success!" );
122
+ break ;
123
+ default :
124
+
125
+ break ;
126
+ }
127
+ // return "";
128
+ // mapper.writeValue(response.getWriter(), rtnData);
129
+ ResponseHelper .writeMapToResponseAsJson (response , rtnData );
130
+ }
131
+
132
+
133
+ @ ModelAttribute ("CMSComment_list" )
134
+ public List <CMSComment > CMSCommentlist () {
135
+ return cMSCommentService .getAllCMSComment ();
136
+ }
137
+ }
0 commit comments