| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169 |
- package com.goafanti.banners.controller;
- import java.util.Calendar;
- import java.util.HashMap;
- import java.util.Map;
- import javax.annotation.Resource;
- import javax.servlet.http.HttpServletRequest;
- import org.springframework.beans.factory.annotation.Autowired;
- import org.springframework.stereotype.Controller;
- import org.springframework.util.Assert;
- import org.springframework.web.bind.annotation.RequestMapping;
- import org.springframework.web.bind.annotation.RequestMethod;
- import com.goafanti.banners.enums.BannersType;
- import com.goafanti.banners.service.BannersService;
- import com.goafanti.common.bo.Result;
- import com.goafanti.common.constant.ErrorConstants;
- import com.goafanti.common.controller.BaseApiController;
- import com.goafanti.common.enums.AttachmentType;
- import com.goafanti.common.model.Banners;
- import com.goafanti.common.utils.StringUtils;
- import com.goafanti.core.mybatis.JDBCIdGenerator;
- @Controller
- @RequestMapping(value = "/api/admin/banners")
- public class AdminBannersApiController extends BaseApiController {
- @Resource
- BannersService bannersService;
- @Autowired
- JDBCIdGenerator idGenerator;
- @RequestMapping(value = "/upload", method = RequestMethod.POST)
- public Result upload(String sign, HttpServletRequest req) {
- Assert.isTrue(StringUtils.isNotBlank(sign) && BannersType.containsType(sign), "广告图位置标示不正确。");
- Result res = res();
- Calendar c = Calendar.getInstance();
- res.data(handleFile(res, false, req, AttachmentType.BANNERS_PIC.getCode(), String.valueOf(c.get(Calendar.YEAR)),
- String.valueOf(c.get(Calendar.MONTH) + 1), idGenerator.generateId().toString()));
- return res;
- }
- /*@RequestMapping(value = "/save", method = RequestMethod.POST)
- public Result save(@Valid Banners banners, BindingResult bindingResult) {
- Assert.notNull(banners, "广告图参数不正确");
- Assert.isTrue(StringUtils.isNotBlank(banners.getSign()) && BannersType.containsType(banners.getSign()),
- "广告图位置标示不正确。");
- Assert.hasText(banners.getImgurl(), "广告图url参数不正确");
- Assert.isTrue(!bindingResult.hasFieldErrors(),
- bindingResult.hasFieldErrors() ? bindingResult.getFieldError().getDefaultMessage() : "");
- Result res = res();
- if (banners.getId() == null) {
- banners.setId(idGenerator.generateId());
- res.data(bannersService.insertBanner(banners));
- } else {
- res.data(bannersService.updateBanner(banners));
- }
- return res;
- }
- @RequestMapping(value = "/list", method = RequestMethod.GET)
- public Result portalBannersList(String key, String pageNo, String pageSize) {
- Assert.isTrue(StringUtils.isBlank(key) || BannersType.containsType(key), "广告图位置标示不正确。");
- Integer pN = getPageNo(pageNo);
- Integer pS = getPageSize(pageSize);
- Map<String, Object> result = new HashMap<>();
- result.put("list", bannersService.findBannersList(key, (pN - 1) * pS, pS));
- result.put("total", bannersService.findBannersListCount(key));
- return res().data(result);
- }
- @RequestMapping(value = "/delete", method = RequestMethod.POST)
- public Result delete(String id) {
- Assert.isTrue(StringUtils.isNumeric(id), "广告图id不正确。");
- return res().data(bannersService.deleteBanner(Long.valueOf(id)));
- }
- @RequestMapping(value = "/clearCache", method = RequestMethod.GET)
- public Result clearCache(String key) {
- Assert.isTrue(StringUtils.isNotBlank(key) && BannersType.containsType(key), "广告图位置标示不正确。");
- bannersService.cleanList(key);
- return res().data(bannersService.findPortalBanners(key));
- }*/
- @RequestMapping(value = "/keys", method = RequestMethod.GET)
- public Result portalBannersKeys() {
- Map<String, String> types = new HashMap<>();
- for (BannersType type : BannersType.values()) {
- types.put(type.getKey(), type.getDesc());
- }
- return res().data(types);
- }
- /**
- * 新增轮播图
- * @param b
- * @return
- */
- @RequestMapping(value="/save" ,method=RequestMethod.POST)
- public Result save(Banners b){
- Result result=new Result();
- result.setData(bannersService.insertBanner(b));
- return result;
- }
- /**
- * 删除轮播图
- * @param id
- * @return
- */
- @RequestMapping(value="/delete" ,method=RequestMethod.POST)
- public Result delete(String id){
- Result result=new Result();
- result.setData(bannersService.deleteBanner(id));
- return result;
- }
- /**
- * 轮播图详情
- * @param id
- * @return
- */
- @RequestMapping(value="/details" ,method=RequestMethod.GET)
- public Result details(String id){
- Result result=new Result();
- result.setData(bannersService.selectByPrimaryKey(id));
- return result;
- }
- /**
- * 修改轮播图
- * @param b
- * @return
- */
- @RequestMapping(value="/update" ,method=RequestMethod.POST)
- public Result details(Banners b){
- Result result=new Result();
- result.setData(bannersService.updateBanner(b));
- return result;
- }
-
- /**
- * 轮播图列表
- * @param apiUrl
- * @param client
- * @param pageSize
- * @param pageNo
- * @param request
- * @return
- */
- @RequestMapping(value="/list" ,method=RequestMethod.GET)
- public Result List(String apiUrl,Integer client,Integer pageSize,Integer pageNo,HttpServletRequest request){
- Result result=new Result();
- result.setData(bannersService.findAdminBannersList( apiUrl,client, pageSize, pageNo));
- return result;
- }
-
-
- /**
- * 图片上传
- */
- @RequestMapping(value = "/uploadPicture", method = RequestMethod.POST)
- public Result uploadPicture(HttpServletRequest req, String sign) {
- Result res = new Result();
- AttachmentType attachmentType = AttachmentType.getField(sign);
- if (attachmentType == AttachmentType.BANNERS_PIC) {
- res.setData(handleFiles(res, "/banners/", false, req, sign, ""));
- } else {
- res.getError().add(buildError(ErrorConstants.PARAM_ERROR, "", "图片标示"));
- }
- return res;
- }
- }
|