InformationController.java
5.7 KB
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
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
package com.server.web.controller;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.server.shiro.persistent.bean.SysUser;
import com.server.utils.DateUtils;
import com.server.web.common.mapper.TBaseSecondClassMapper;
import com.server.web.common.mapper.TKzyCourseMapper;
import com.server.web.common.mapper.TKzyInformationMapper;
import com.server.web.common.model.PageModel;
import com.server.web.common.model.TBaseSecondClass;
import com.server.web.common.model.TKzyCourse;
import com.server.web.common.model.TKzyInformation;
import com.server.web.common.service.CourseService;
import com.server.web.common.service.InformationService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/**
* 资讯管理
*/
@RestController
@RequestMapping(BaseController.OSS_NAMESPACE + "/information")
public class InformationController extends BaseController {
@Autowired
private TKzyInformationMapper informationMapper;
@Autowired
private InformationService informationService;
@Autowired
private TBaseSecondClassMapper secondClassMapper;
/**
* 资讯列表
* @param title
* @param pageNo
* @param pageSize
* @return
*/
@ResponseBody
@RequestMapping(path = "/informationList", method = {RequestMethod.POST, RequestMethod.GET}, produces = "application/json")
public Map informationList(@RequestParam(defaultValue = "") String title
,@RequestParam(defaultValue = "1") Integer pageNo, @RequestParam(defaultValue = "1") Integer pageSize) {
try {
Map paramMap = new HashMap<>();
if(!("").equals(title)){
paramMap.put("title","%"+title+"%");
}
PageHelper.startPage(pageNo,pageSize,true,false);
List list = openSqlRingsService.selectList_Rings("com.mapping.queryModel.queryInformation",paramMap);
PageInfo pageInfo = new PageInfo(list);
PageModel model = new PageModel();
model.setTotal(pageInfo.getTotal());
model.setList(list);
return success(model);
} catch (Exception e) {
e.printStackTrace();
return error("0","系统异常",null);
}
}
/**
* 删除资讯
* @param id
* @return
*/
@ResponseBody
@RequestMapping(path = "/deleteInformation", method = {RequestMethod.POST, RequestMethod.GET}, produces = "application/json")
public Map deleteInformation(@RequestParam long id) {
try {
TKzyInformation information = new TKzyInformation();
information.setId(id);
information.setIsDelete(1);
information.setUpdateDt(new Date());
informationMapper.updateByPrimaryKeySelective(information);
return success("操作成功");
} catch (Exception e) {
e.printStackTrace();
return error("0","系统异常",null);
}
}
@ResponseBody
@RequestMapping(path = "/saveInformation", method = {RequestMethod.POST, RequestMethod.GET}, produces = "application/json")
public Map saveInformation(@RequestParam(defaultValue = "-1") long id,@RequestParam String title,@RequestParam String author,@RequestParam String content,
@RequestParam String picUrl,@RequestParam String iconUrl,@RequestParam(defaultValue = "") String classIds
) {
try {
String [] ids = classIds.split(",");
boolean flag = true;
for (int i=0;i<ids.length;i++){
TBaseSecondClass secondClass = secondClassMapper.selectByPrimaryKey(Long.valueOf(ids[i]));
if(secondClass.getType()!=1){
flag = false;
break;
}
}
if(!flag){
return error("0","分类类型不匹配","分类类型不匹配");
}
TKzyInformation information = new TKzyInformation();
information.setTitle(title);
information.setPicUrl(picUrl);
information.setAuthor(author);
// information.setContent();
information.setIconUrl(iconUrl);
if(id != -1){ //修改
information.setId(id);
information.setUpdateDt(new Date());
informationService.updateInformation(information,classIds);
}else{ //添加
information.setCreateDt(new Date());
information.setIsDelete(0);
informationService.insertInformation(information,classIds);
}
return success("操作成功");
} catch (Exception e) {
e.printStackTrace();
return error("0","系统异常",null);
}
}
/**
* 资讯详情
* @param id
* @return
*/
@ResponseBody
@RequestMapping(path = "/informationInfo", method = {RequestMethod.POST, RequestMethod.GET}, produces = "application/json")
public Map informationInfo(@RequestParam long id) {
try {
Map paramMap = new HashMap<>();
paramMap.put("id",id);
paramMap.put("type",2);
Map map = (Map)openSqlRingsService.selectOne_Rings("com.mapping.queryModel.queryInformationInfo",paramMap);
List classList = openSqlRingsService.selectList_Rings("com.mapping.queryModel.queryCourseClass",paramMap);
map.put("classList",classList);
return success(map);
} catch (Exception e) {
e.printStackTrace();
return error("0","系统异常",null);
}
}
}