BannerAction.java
4.45 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
package com.cjs.cms.action.site;
import java.io.IOException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Map;
import org.apache.commons.lang3.StringUtils;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import com.cjs.cms.biz.site.UploadBiz;
import com.cjs.cms.dao.site.BannerDao;
import com.cjs.cms.model.site.BannerInfo;
import com.cjs.cms.model.user.UserInfo;
import com.cjs.cms.util.file.FileUtil;
import com.cjs.cms.util.lang.JsonUtil;
import com.cjs.cms.util.lang.PageUtils;
import com.cjs.cms.util.lang.StringUtil;
import com.cjs.cms.util.web.ActionUtil;
/**
* 广告轮换
*
* @author kongmingke
*
*/
@RestController
@RequestMapping("/banner")
public class BannerAction {
@Autowired
private BannerDao bannerDao;
@Autowired
private UploadBiz upload;
Logger log = LogManager.getLogger();
@RequestMapping("/searchList")
public String getBannerList(@RequestParam Map<String, Object> params) {
if (StringUtil.isBlank(params.get("beginDate"))) {
params.put("beginDate", null);
}
if (StringUtil.isBlank(params.get("endDate"))) {
params.put("endDate", null);
}
PageUtils.processPage(params);
return JsonUtil.toPageJson(bannerDao.getBannerList(params),
bannerDao.getBannerListCount(params));
}
/**
* 新增广告图片
*
* @param params
*/
@RequestMapping("/addOrUpdateBanner")
public String addOrUpdateBanner(BannerInfo banner) {
String resultCode = "0";
// 获取当前登录人信息
UserInfo userInfo = (UserInfo) ActionUtil.getRequest().getSession()
.getAttribute(UserInfo.USER);
if (StringUtils.isNotBlank(banner.getTitleFile().getOriginalFilename())) {
// 图片名称
String imageName = FileUtil.QueryArticleImgPrefix()
+ FileUtil.getSuffix(banner.getTitleFile().getOriginalFilename());
Map<String, String> map = upload.markFile();
// 图片上传路径
String imgTargetFile = map.get("uploadPath") + "/" + imageName;
banner.setImage(map.get("imageUrl") + "/" + imageName);
try {
FileUtil.transferFile(banner.getTitleFile(), imgTargetFile);
} catch (IOException e) {
log.error("", e);
resultCode = "-1";
}
}
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss");
if (StringUtils.isBlank(banner.getStartAt())) {
banner.setStartAt(sdf.format(new Date()));
}
if (StringUtils.isBlank(banner.getEndAt())) {
banner.setEndAt("2099-12-30 00:00:00");
}
if (resultCode == "0") {
// 修改
if (banner.getId() != null && banner.getId() != 0) {
banner.setUpdateBy(userInfo.getUsername());
bannerDao.updateBanner(banner);
// 增加
} else {
if (banner.getBannerLocation() == 1) {
int hangqing = bannerDao.getBannerLocationCount(banner.getBannerLocation());
if (hangqing > 0) {
resultCode = "-2";
}
}
if (banner.getBannerLocation() == 2) {
int kaihu = bannerDao.getBannerLocationCount(banner.getBannerLocation());
if (kaihu > 0) {
resultCode = "-3";
}
}
if (resultCode != "-2" && resultCode != "-3") {
banner.setCreateBy(userInfo.getUsername());
banner.setUpdateBy(userInfo.getUsername());
bannerDao.addBanner(banner);
}
}
}
return JsonUtil.toJson("resultCode", resultCode);
}
/**
* 删除广告图片
*
* @param params
*/
@RequestMapping("/deleteBanner")
public String deleteBanner(String ids) {
for (String id : ids.split(",")) {
bannerDao.deleteBanner(Integer.parseInt(id));
}
return JsonUtil.toJson("resultCode", "0");
}
}