Browse Source

news upload

Antiloveg 8 years ago
parent
commit
bc5925275b

+ 22 - 5
src/main/java/com/goafanti/admin/controller/AdminNewsApiController.java

@@ -4,6 +4,7 @@ import java.text.ParseException;
 import java.util.Arrays;
 
 import javax.annotation.Resource;
+import javax.servlet.http.HttpServletRequest;
 import javax.validation.Valid;
 
 import org.springframework.beans.BeanUtils;
@@ -18,10 +19,12 @@ import com.goafanti.common.bo.Result;
 import com.goafanti.common.constant.AFTConstants;
 import com.goafanti.common.constant.ErrorConstants;
 import com.goafanti.common.controller.BaseApiController;
+import com.goafanti.common.enums.AttachmentType;
 import com.goafanti.common.model.News;
 import com.goafanti.common.utils.DateUtils;
 import com.goafanti.common.utils.StringUtils;
 import com.goafanti.core.mybatis.JDBCIdGenerator;
+import com.goafanti.core.shiro.token.TokenManager;
 import com.goafanti.news.bo.InputNews;
 import com.goafanti.news.enums.NewsFields;
 import com.goafanti.news.service.NewsService;
@@ -33,7 +36,7 @@ import com.goafanti.news.service.NewsService;
 @RequestMapping(value = "/api/admin/news")
 public class AdminNewsApiController extends BaseApiController {
 	@Resource
-	private NewsService newsService;
+	private NewsService		newsService;
 	@Autowired
 	private JDBCIdGenerator	idGenerator;
 
@@ -103,12 +106,12 @@ public class AdminNewsApiController extends BaseApiController {
 		newsService.update(news.getId(), (News) res.getData());
 		return res;
 	}
-	
+
 	/**
 	 * 详情
 	 */
 	@RequestMapping(value = "/detail", method = RequestMethod.GET)
-	public Result detail(Long id){
+	public Result detail(Long id) {
 		Result res = new Result();
 		if (null == id) {
 			res.getError().add(buildError(ErrorConstants.PARAM_EMPTY_ERROR, "", "新闻Id"));
@@ -117,7 +120,7 @@ public class AdminNewsApiController extends BaseApiController {
 		res.setData(newsService.findNewsDetail(id));
 		return res;
 	}
-	
+
 	/**
 	 * 删除
 	 */
@@ -132,6 +135,20 @@ public class AdminNewsApiController extends BaseApiController {
 		return res;
 	}
 	
+	/**
+	 * 新闻图片上传
+	 */
+	@RequestMapping(value = "/upload", method = RequestMethod.POST)
+	public Result upload(HttpServletRequest req, String sign) {
+		Result res = new Result();
+		AttachmentType attachmentType = AttachmentType.getField(sign);
+		if (attachmentType == AttachmentType.NEWS_PIC) {
+			res.setData(handleFiles(res, "/news/", false, req, sign, TokenManager.getAdminId()));
+		} else {
+			res.getError().add(buildError(ErrorConstants.PARAM_ERROR, "", "附件标示"));
+		}
+		return res;
+	}
 
 	private Result disposeInputNews(Result res, InputNews news, String createTimeFormattedDate) {
 		if (StringUtils.isBlank(news.getTitle())) {
@@ -158,5 +175,5 @@ public class AdminNewsApiController extends BaseApiController {
 		res.setData(n);
 		return res;
 	}
-	
+
 }

+ 1 - 0
src/main/java/com/goafanti/common/enums/AttachmentType.java

@@ -43,6 +43,7 @@ public enum AttachmentType {
 	BANNERS_PIC("banners", "广告图片"),
 	NEWS_PIC("news", "新闻图片"),
 	LECTURE_PICTURE("lecture_picture", "科技讲堂展示图片");
+	
 
 	private AttachmentType(String code, String desc) {
 		this.code = code;

+ 2 - 1
src/main/java/com/goafanti/common/utils/FileUtils.java

@@ -105,7 +105,8 @@ public class FileUtils {
 				|| sign.indexOf("demand_picture") != -1 || sign.indexOf("demand_text_file") != -1
 				|| sign.indexOf("achievement_technical_picture") != -1
 				|| sign.indexOf("achievement_maturity_picture") != -1 || sign.indexOf("demand_order_file") != -1
-				|| sign.indexOf("lecture_picture") != -1) {
+				|| sign.indexOf("lecture_picture") != -1
+				|| sign.indexOf("news") != -1) {
 			uniq = true;
 		}
 		String fileName = "";