package com.jb.web.controller;
import com.alibaba.dubbo.config.annotation.Reference;
import com.alibaba.fastjson.JSON;
import com.jb.core.base.AjaxResult;
import com.jb.core.base.PageResult;
import com.jb.core.base.RequestPath;
import com.jb.core.dd.DataDictionary;
import com.jb.core.exception.InputParamsNullException;
import com.jb.core.io.FastDFSUtil;
import com.jb.entity.Brand;
import com.jb.facade.service.BrandCenterService;
import com.jb.log.Log;
import org.csource.common.MyException;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import java.io.IOException;
import java.util.List;
import java.util.Map;
/**
* 品牌管理控制器
* Created by 27654 on 2018/10/19.
*/
@Controller
@RequestMapping("/" + BrandController.DOMAIN)
public class BrandController {
public static final String DOMAIN = "brand";
@Reference(check = false)
private BrandCenterService brandCenterService;
@Value("${fileServerIP}")
private String fileServerIP; //文件服务器IP地址
/**
* 分页查找品牌数据
*
* @param row 当前页
* @param length 页长
* @param search 搜索条件
* @return Ajax 统一格式返回结果集
*/
@ResponseBody
@RequestMapping(value = RequestPath.RESTFUL + RequestPath.JSON, method = RequestMethod.GET)
public String get(@PathVariable("value") Long row, @RequestParam(value = "length", required = false) Integer length,
@RequestParam(required = false) Map<String, Object> search) {
AjaxResult ajRs = null;
try {
System.err.println("SEARCH == " + JSON.toJSONString(search));
PageResult page = new PageResult(row, length, search);
page = brandCenterService.getBrand(page);
ajRs = new AjaxResult(DataDictionary.OK, page);
} catch (InputParamsNullException e) {
Log.logger.error(e.getMessage(), e);
return new AjaxResult(DataDictionary.PARAMS_NULL, "err/404").toJSON();
} catch (Exception e) {
Log.logger.error(e.getMessage(), e);
return new AjaxResult(DataDictionary.NET_BAD, "err/500").toJSON();
}
return ajRs.toJSON();
}
/**
* 文件上传接口定义
*
* @param file 文件流
* @return 图片绝对地址
*/
@ResponseBody
@RequestMapping(value = RequestPath.UPLOAD, method = RequestMethod.POST)
public String upload(@RequestParam MultipartFile file) {
AjaxResult ajRs = null;
if (file == null || file.isEmpty()) {
return new AjaxResult(DataDictionary.PARAMS_NULL).toJSON();
}
try {
FastDFSUtil dfsUtil = new FastDFSUtil();
String path = dfsUtil.uploadFile(file.getOriginalFilename(), file.getBytes());
String src = "http://" + fileServerIP + "/" + path;
ajRs = new AjaxResult(DataDictionary.SUCCESS, src);
} catch (Exception e) {
Log.logger.error(e.getMessage(), e);
return new AjaxResult(DataDictionary.NET_BAD).toJSON();
}
return ajRs.toJSON();
}
/**
* 更新保存品牌信息
*
* @param brand 品牌基本信息
* @param url 将要删除的图片
* @return AJAX统一格式结果集
*/
@ResponseBody
@RequestMapping(value = RequestPath.SAVE, method = RequestMethod.POST)
public String save(Brand brand, @RequestParam(value = "url", required = false) String url) {
int row;
FastDFSUtil dfsUtil = new FastDFSUtil();
AjaxResult ajaxRs = null;
if (brand == null) {
return new AjaxResult(DataDictionary.PARAMS_NULL).toJSON();
}
try {
if (brand.getId() == null || brand.equals("")) {
row = brandCenterService.addBrand(brand);
} else {
row = brandCenterService.editerBrand(brand);
}
if (row > 0) {
ajaxRs = new AjaxResult(DataDictionary.SUCCESS);
if (url != null) {
String group = url.substring(url.indexOf("group"));
dfsUtil.delete_file(group);
}
} else {
ajaxRs = new AjaxResult(DataDictionary.FAILED);
}
} catch (Exception e) {
Log.logger.error(e.getMessage(), e);
if (brand.getLogo() != null) {
try {
dfsUtil.delete_file(brand.getLogo()); //删除文件
} catch (IOException e1) {
Log.logger.error(e.getMessage(), e);
} catch (MyException e1) {
Log.logger.error(e.getMessage(), e);
}
}
ajaxRs = new AjaxResult(DataDictionary.NET_BAD);
}
return ajaxRs.toJSON();
}
/**
* 删除指定id的品牌
*
* @param id 删除的id
* @return 统一结果集
*/
@ResponseBody
@RequestMapping(value = RequestPath.RESTFUL + RequestPath.DELET, method = RequestMethod.POST)
public String delete(@PathVariable("value") Long id, @RequestParam("url") String url) {
AjaxResult ajaxRs;
System.err.println("URL === " + id);
if (id == null) {
return new AjaxResult(DataDictionary.PARAMS_NULL).toJSON();
}
try {
int row = brandCenterService.delBrand(id);
if (row > 0) {
if (url != null) { //删除图片
String group = url.substring(url.indexOf("group"));
new FastDFSUtil().delete_file(group);
}
ajaxRs = new AjaxResult(DataDictionary.SUCCESS);
} else {
ajaxRs = new AjaxResult(DataDictionary.FAILED);
}
} catch (InputParamsNullException e) {
Log.logger.error(e.getMessage(), e);
return new AjaxResult(DataDictionary.NET_BAD).toJSON();
} catch (Exception e) {
Log.logger.error(e.getMessage(), e);
return new AjaxResult(DataDictionary.NET_BAD).toJSON();
}
return ajaxRs.toJSON();
}
@ResponseBody
@RequestMapping(value = RequestPath.RESTFUL + RequestPath.SEARCH, method = RequestMethod.GET)
public String getBrand(@PathVariable("value") String name) {
AjaxResult ajaxRs = null;
try {
if(name == null || name.equals("")){
return new AjaxResult(DataDictionary.PARAMS_NULL).toJSON();
}
List<Brand> brands = brandCenterService.getBrands(name);
ajaxRs = new AjaxResult(DataDictionary.SUCCESS, brands);
} catch (Exception e) {
Log.logger.error(e.getMessage(), e);
ajaxRs = new AjaxResult(DataDictionary.NET_BAD);
}
return ajaxRs.toJSON();
}
}
没有合适的资源?快使用搜索试试~ 我知道了~
佳贝网是一个b2模式的电商网站,采用分布式、集群模式开发,使用Spring+SpringMVC+mybatis框架开发.zip
共784个文件
gif:308个
js:84个
xml:60个
需积分: 5 0 下载量 73 浏览量
2023-09-29
19:49:42
上传
评论
收藏 29.89MB ZIP 举报
温馨提示
佳贝网是一个b2模式的电商网站,采用分布式、集群模式开发,使用Spring+SpringMVC+mybatis框架开发
资源推荐
资源详情
资源评论
收起资源包目录
佳贝网是一个b2模式的电商网站,采用分布式、集群模式开发,使用Spring+SpringMVC+mybatis框架开发.zip (784个子文件)
BrandController.class 7KB
BrandController.class 7KB
Product.class 5KB
Project.class 5KB
ProductTypeCenterServiceImpl.class 4KB
ProductTypeController.class 4KB
ProductTypeController.class 4KB
SKU.class 4KB
ProductController.class 4KB
ProductController.class 4KB
ProductType.class 4KB
TestFastDFS.class 3KB
BrandCenterServiceImpl.class 3KB
PageResult.class 3KB
Brand.class 3KB
TestBrand.class 3KB
ProductCenterServiceImpl.class 3KB
DataDictionary.class 3KB
Property.class 3KB
FastDFSUtil.class 2KB
ProductViewProperty.class 2KB
SkuProperty.class 2KB
ProductMedia.class 2KB
ProductComment.class 2KB
ProductExt.class 2KB
PropertyOption.class 2KB
TestDubbo.class 2KB
AjaxResult.class 2KB
TestProductTypeService.class 1KB
PlatController.class 1KB
PlatController.class 1KB
ProductProperty.class 1KB
TestDubboService.class 1KB
BrandMapper.class 929B
ProductTypeMapper.class 898B
ProductTypeCenterService.class 801B
ProductCenterService.class 662B
ProductCenterService.class 662B
BrandCenterService.class 621B
BrandCenterService.class 621B
ProductTypeCenterService.class 584B
RequestPath.class 553B
ProductCommentMapper.class 507B
InputParamsNullException.class 489B
ProductTypeServiceImpl.class 456B
ProductExtMapper.class 431B
ProductViewPropertyMapper.class 429B
ProductPropertyMapper.class 413B
PropertyOptionMapper.class 409B
ProductMediaMapper.class 401B
SkuPropertyMapper.class 397B
PropertyMapper.class 385B
SKUMapper.class 365B
Log.class 340B
StateCode.class 230B
ProductTypeServiceI.class 134B
selectmenu.css 36KB
selectmenu.css 36KB
font-awesome.min.css 32KB
font-awesome.min.css 32KB
default.css 20KB
default.css 20KB
iui.css 11KB
iui.css 11KB
laydate.css 8KB
laydate.css 8KB
home.css 3KB
home.css 3KB
qq.css 3KB
qq.css 3KB
product.css 2KB
product.css 2KB
index.css 2KB
index.css 2KB
selectFilter.css 2KB
selectFilter.css 2KB
simple.css 2KB
simple.css 2KB
brand.css 2KB
brand.css 2KB
commom.css 1KB
commom.css 1KB
productType.css 1KB
productType.css 1KB
addProduct.css 1KB
addProduct.css 1KB
prettify.css 960B
prettify.css 960B
fontawesome-webfont.eot 162KB
fontawesome-webfont.eot 162KB
iconfont.eot 2KB
iconfont.eot 2KB
1.gif 103KB
1.gif 103KB
static.gif 35KB
static.gif 35KB
35.gif 13KB
35.gif 13KB
42.gif 13KB
42.gif 13KB
共 784 条
- 1
- 2
- 3
- 4
- 5
- 6
- 8
资源评论
天天501
- 粉丝: 605
- 资源: 4666
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功