基于javaweb+mysql的ssm在线图书商城系统(java+ssm+freemarker+bootstrap+mysql+redis)
运行环境
Java≥8、MySQL≥5.7、Tomcat≥8
开发工具
eclipse/idea/myeclipse/sts等均可配置运行
适用
课程设计,大作业,毕业设计,项目练习,学习演示等
功能说明
基于javaweb+mysql的SSM在线图书商城系统(java+ssm+freemarker+bootstrap+mysql+redis)
项目介绍
本项目分为前后台,有管理员与用户两种角色; 管理员角色包含以下功能: 管理员登录,商品分类管理,商品管理,商品属性管理,商品参数管理,订单管理,退款管理,退货管理,会员等级管理,客户信息管理,评论管理,文章分类管理,公告管理,文章管理,滚动图片管理,广告管理,热门查询管理,查询订单销售,查询商品销售,用户管理,角色管理,资源管理,修改密码,区域管理,配送方式管理,查看系统设置,缓存管理,查询到货通知等功能。
用户角色包含以下功能: 用户登录,查看首页,查看商品详情,查看购物车,提交订单,修改个人信息,修改密码,查看我的订单,添加配送地址,查看收藏夹等功能。
环境需要
1.运行环境:最好是java jdk 1.8,我们在这个平台上运行的。其他版本理论上也可以。 2.IDE环境:Eclipse;注:本项目目前仅支持Eclipse,暂不支持IDEA; 3.tomcat环境:Tomcat 7.x,8.x,9.x版本均可 4.硬件环境:windows 7/8/10 1G内存以上;或者 Mac OS; 5.数据库:MySql 5.7版本; 6.是否Maven项目:否;
技术栈
- 后端:Spring+SpringMVC+Mbytes 2. 前端:Freemarker+css+javascript+bootstrap+jQuery
使用说明
- 使用Navicat或者其它工具,在mysql中创建对应名称的数据库,并导入项目的sql文件; 2. 使用Eclipse导入项目,将项目中src目录下的conf.properties配置文件中的数据库配置改为自己的配置; 3. 运行项目,在浏览器中输入localhost:8080/ssm_zxbookshop 用户账号/密码: user/123456 管理员账号/密码:admin/admin
private void appendChildren(Catalog catalog, List<Catalog> list) {
if(catalog == null){
return;
}
list.add(catalog);
if(catalog.getChildren() != null && catalog.getChildren().size() > 0) {
for (Catalog cata : catalog.getChildren()) {
appendChildren(cata, list);
}
}
}
public void setCatalogService(CatalogService catalogService) {
this.catalogService = catalogService;
}
@Override
public void insertAfter(Catalog e) {
}
/**
* 递归查询数据库获取商品目录
* 返回tree的数据结构 从PID=0开始加载菜单资源 获取指定节点的全部子菜单(包括当前菜单节点)
*
* @return
* @throws Exception
*/
@RequestMapping("getRoot")
@ResponseBody
public String getRoot(Catalog e) throws Exception {
List<Catalog> root = catalogService.loadRoot(e);
JSONArray json = JSONArray.fromObject(root);
logger.debug("catalog json : " + json.toString());
String jsonStr = json.toString();
return jsonStr;
}
/**
* 数据来自缓存
* 返回适合easyui.treegrid的JSON的数据结构 从PID=0开始加载菜单资源 获取指定节点的全部子菜单(包括当前菜单节点)
*
* @return
* @throws Exception
*/
@RequestMapping("getRootWithTreegrid")
@ResponseBody
public String getRootWithTreegrid(Catalog e) throws Exception {
logger.error(">>>selectList type = "+e.getType());
List<net.jeeshop.services.front.catalog.bean.Catalog> root = null;
if(e.getType().equals("p")){
param.put("pid", menu.getPid());
//加载菜单节点
List<Menu> data = menuService.selectList(param);
if(data==null || data.size()==0){
return;
}
if(item.getChildren()==null)item.setChildren(new ArrayList<MenuItem>());
//创建菜单节点
for (int i = 0; i < data.size(); i++) {
Menu entry = data.get(i);
MenuItem addItem = new MenuItem(entry.getName(), null);
addItem.setId(entry.getId());
addItem.setPid(entry.getPid());
addItem.setMenuType(entry);
String url0 = null;
if(url!=null){
addItem.setUrl(url);
url0 = url;
}else{
addItem.setUrl(entry.getUrl());
url0 = entry.getUrl();
}
// System.out.println("entry.getType()="+entry.getType()+",MenuType.button="+MenuType.button);
if(entry.getType().equals("button")){
addUserResourceMenusButton(url0);
}else{
item.getChildren().add(addItem);
}
}
//根据菜单节点进行递归加载
for (int i = 0; i < item.getChildren().size(); i++) {
MenuItem childItem = item.getChildren().get(i);
if(!childItem.isButton()){
Menu itemMenu = new Menu();
itemMenu.setPid(childItem.getId());
// itemMenu.setMenuType(entry);
loadChildrenByPid(childItem, itemMenu,url,u);
}
}
}
@RequestMapping(value = "save", method = RequestMethod.POST)
public String save(@ModelAttribute("e") Menu menu) throws Exception {
if (menu.getId() == null || menu.getId().equals("")) {
systemManager.setArticleCatalogJsonStr(articleCatalogJsonStr);
logger.debug("article catalog json str : {}", articleCatalogJsonStr);
return articleCatalogJsonStr;
}else{
throw new IllegalAccessError("参数异常。");
}
}
/**
* 根据ID删除指定的目录,如果该类目下面有子类目,则会一并删除;如果该类目下面有商品,则会一并删除
*
* @return
* @throws Exception
*/
@RequestMapping(value = "deleteByID", method = RequestMethod.POST)
@ResponseBody
public String deleteByID(String id) throws Exception {
if (StringUtils.isBlank(id)) {
throw new NullPointerException("参数不正确!");
}
boolean isSuccess = catalogService.deleteByID(id);
logger.info("delete resule : {}", isSuccess);
reset();
return String.valueOf(isSuccess);
}
/**
* 添加/修改/删除 某一个类别后,需要重新加载缓存数据。并且清除JSON字符串缓存,以便重新生成新的。
* @throws Exception
*/
private void reset() throws Exception {
systemManager.setProductCatalogJsonStr(null);
systemManager.setArticleCatalogJsonStr(null);
frontCache.loadCatalogs(true);//同步更新缓存
}
/**
* 不支持批量删除
*/
@Override
public String deletes(HttpServletRequest request, String[] ids, Catalog e, RedirectAttributes flushAttrs) throws Exception {
throw new NullPointerException();
}
}
}
//保存商品参数
// e.setParameterIds(RequestHolder.getRequest().getParameterValues("id"));
// e.setParameterNames(RequestHolder.getRequest().getParameterValues("parameterValue"));
if(e.getParameterNames()!=null && e.getParameterNames().length>0){
for(int i=0;i<e.getParameterNames().length;i++){
String pName = e.getParameterNames()[i];
if(StringUtils.isBlank(pName)){
continue;
}
//插入数据到属性中间表
Attribute_link attrLink = new Attribute_link();
attrLink.setAttrID(Integer.valueOf(e.getParameterIds()[i]));
attrLink.setValue(pName);
attrLink.setProductID(Integer.valueOf(e.getId()));
attribute_linkService.insert(attrLink);
}
}
}
/**
* 例如:http://127.0.0.1:8082/myshop/upload/1.jpg;http://127.0.0.1:8082/myshop/upload/2.jpg;
* 获取产品图片路径,注意,这个应该都是相对路径,因为图片有可能会放到专门的图片服务器上。
* @return
*/
private String getImagesPath(Product e, String appendImgs){
logger.error("e.images = "+e.getImages());
// if(StringUtils.isBlank(e.getImages())){
// return null;
// }
Set<String> imagesSet = new HashSet<String>();
//添加库里面查询出的图片
if(StringUtils.isNotBlank(appendImgs)){
String[] images2 = appendImgs.split(ManageContainer.product_images_spider);
for(int i=0;i<images2.length;i++){
if(StringUtils.isNotBlank(images2[i])){
imagesSet.add(images2[i].trim());
}
}
}
//添加页面上传的图片
String[] images = e.getImages().split(ManageContainer.product_images_spider);
for(int i=0;i<images.length;i++){
// List<Address> addressList = addressService.selectList(add);
// cartInfo.setAddressList(addressList);
// if(addressList!=null && addressList.size()>0){
boolean exist = false;
// for(int i=0;i<addressList.size();i++){
// Address addItem = addressList.get(i);
// if(StringUtils.isNotBlank(addItem.getIsdefault()) && addItem.getIsdefault().equals("y")){
// cartInfo.setDefaultAddessID(addItem.getId());
// break;
// }
// }
// }
// logger.error("cartInfo="+cartInfo);
// return "cart";
}
/**
* 从购物车中删除指定的产品
* @return
*/
@RequestMapping(value = "delete", method = RequestMethod.POST)
public String delete(ModelMap model, String id){
if(StringUtils.isBlank(id)){
throw new NullPointerException("非法请求!");
}
CartInfo cartInfo = getMyCart();
if(cartInfo==null){
//会话超时,转到登陆页面
return page_toLoginRedirect;
}
for(Iterator<Product> it = cartInfo.getProductList().iterator();it.hasNext();){
Product p = it.next();
if(p.getId().equals(id)){
it.remove();
//重新计算总支付金额
// cartInfo.setAmount(cartInfo.totalCacl());
cartInfo.totalCacl();
break;
}
}
return "redirect:/cart/cart.html";
}
DecimalFormat df = new DecimalFormat("0.00");
/**
* 加入购物车,不对金额进行任何的运算。金额的运算在方法CartAction.notifyCart
* @return
* @throws IOException
*/
String result = null;
synchronized (FrontContainer.insert_favorite_lock) {
if(favoriteService.selectCount(favorite) == 0){
favoriteService.insert(favorite);
result = "0";//添加成功
}else{
result = "1";//已经添加过了
}
}
return (result);
}
/**
* 商品到货通知-ajax
* @return
* @throws IOException
*/
@RequestMapping("insertEmailNotifyProductService")
@ResponseBody
public String insertEmailNotifyProductService(Product product) throws IOException{
String productID = RequestHolder.getRequest().getParameter("productID");
String receiveEmail = RequestHolder.getRequest().getParameter("receiveEmail");
String productName = RequestHolder.getRequest().getParameter("productName");
if(StringUtils.isBlank(productID) || StringUtils.isBlank(receiveEmail)){
throw new NullPointerException(FrontContainer.request_illegal_error);
}
Account acc = getLoginAccount();
if(acc==null){
return ("-1");//用户需要登录
}
EmailNotifyProduct info = new EmailNotifyProduct();
info.setAccount(acc.getAccount());
info.setReceiveEmail(receiveEmail);
info.setProductID(productID);
info.setProductName(productName);
info.setStatus(EmailNotifyProduct.emailNotifyProduct_status_n);
emailNotifyProductService.insert(info);
return ("0");//成功
}
/**
* 加载促销活动的商品列表
* @return
* @throws Exception
*/
@RequestMapping("activity/{code}")
public String activity(ModelMap model, @ModelAttribute("code")@PathVariable("code")String code) throws Exception{
logger.error("activityProductList...");
List<Product> productList;
attr.setPid(-1);
attr = this.attributeService.selectOne(attr);//加载参数主属性,一个参数下包含多个子参数
if(attr!=null){
//加载每个属性下的子属性列表
int id = Integer.valueOf(attr.getId());
attr.clear();
attr.setPid(id);
// attr.setPid(0);
attr.setCatalogID(0);
//@@@
e.setParameterList(this.attributeService.selectList(attr));
}
//如果商品ID不存在,则不加载商品选中的参数列表
if(StringUtils.isBlank(e.getId())){
return;
}
//加载商品参数
if(e.getParameterList()!=null && e.getParameterList().size()>0){
Attribute_link attrLink = new Attribute_link();
attrLink.setProductID(Integer.valueOf(e.getId()));
//查询参数列表
List<Attribute_link> attrLinkList = attribute_linkService.selectList(attrLink);
if(attrLinkList!=null && attrLinkList.size()>0){
for(int i=0;i<e.getParameterList().size();i++){//循环主属性
Attribute itemInfo = e.getParameterList().get(i);
int _attrID = Integer.valueOf(itemInfo.getId());
for(int k=0;k<attrLinkList.size();k++){//循环用户选择的属性
Attribute_link al = attrLinkList.get(k);
if(al.getAttrID()==_attrID){
itemInfo.setParameterValue(al.getValue());
break;
}
}
}
}
}
}
/**
* 根据商品分类加载商品属性列表
* @catalogID 商品类别ID
*/
private void loadAttribute(Product e, int catalogID) {
private boolean requireLogin() throws NullPointerException{
Account account = LoginUserHolder.getLoginAccount();
if (account == null || StringUtils.isBlank(account.getAccount())) {
return true;
}
return false;
}
/**
* 配送地址管理
* @return
*/
@RequestMapping("address")
public String address(ModelMap model, Address address){
Account account = LoginUserHolder.getLoginAccount();
if (account == null || StringUtils.isBlank(account.getAccount())) {
return toLogin;
}
// selectLeftMenu = "address";
address.setAccount(account.getAccount());
List<Address> addressList = addressService.selectList(address);
model.addAttribute("address", address);
model.addAttribute("addressList", addressList);
Map<String, Area> areaMap = SystemManager.getInstance().getAreaMap();
model.addAttribute("provinces", areaMap.values());
List<Area> cities = new ArrayList<Area>();
List<Area> areas = new ArrayList<Area>();
if(StringUtils.isNotBlank(address.getProvince()) && areaMap.get(address.getProvince()) != null) {
cities = areaMap.get(address.getProvince()).getChildren();
}
model.addAttribute("cities", cities);
String area = address.getArea();
for(Area a : cities){
if(a.getCode().equals(area)){
areas = a.getChildren();
break;
}
}
//TODO 缓存的地址只有二级,没有区县
model.addAttribute("areas", areas);
return "/account/address";
}
/**
* 增加配送地址
* @return
*/
@RequestMapping("saveAddress")
public String saveAddress(ModelMap model, Address address) {
Account acc = LoginUserHolder.getLoginAccount();
if (acc == null || StringUtils.isBlank(acc.getAccount())) {
return toLogin;
// product0.setCatalogID(refp.getCatalogID());
// product0.setPicture(refp.getPicture());
// product0.setPrice(refp.getPrice());
// product0.setNowPrice(refp.getNowPrice());
// product0.setSellcount(refp.getSellcount());
// product0.setStock(refp.getStock());
// product0.setIsnew(refp.getIsnew());
// product0.setSale(refp.getSale());
// product0.setTitle(refp.getTitle());
// product0.setDescription(refp.getDescription());
// product0.setKeywords(refp.getKeywords());
// product0.setIntroduce(refp.getIntroduce());
// product0.setImages(refp.getImages());
// product0.setProductHTML(refp.getProductHTML());
// product0.setStatus(refp.getStatus());
//
// productService.insert(product0);
// }
// return selectList();
// }
// public String test2() throws IOException{
// List<Product> list = productService.selectList(new Product());
// for(int i=0;i<list.size();i++){
// Product pp = list.get(i);
// if(StringUtils.isNotBlank(pp.getProductHTML())){
//
// Product ppp = new Product();
// ppp.setId(pp.getId());
// ppp.setProductHTML(pp.getProductHTML().replace("http://jeeshopxx.oss.aliyuncs.com/", "http://myshopxx.oss.aliyuncs.com/"));
//
// logger.error(">>>test2>>"+ppp.getProductHTML());
// productService.update(ppp);
// }
// }
//
// getResponse().getWriter().write("success");
// return null;
// }
/**
* 把所有商品的大图更新为小图
* @return
*/
public String test10() {
logger.error("test10...");
List<Product> list = productService.selectList(new Product());
for (int i = 0; i < cartInfo.getProductList().size(); i++) {
Product product = cartInfo.getProductList().get(i);
if(productStockMap.get(product.getId())==null){
product.product_sorry_str = "抱歉,该商品目前库存不足!";
no = true;
continue;
}
ProductStockInfo stockInfo = productStockMap.get(product.getId());
if(product.getBuyCount() > stockInfo.getStock()){
//如果用户购买的某个商品的数量大于该商品的库存数,则提示
product.product_sorry_str = "抱歉,该商品目前库存不足!";
no = true;
}
}
//库存不足,则刷最后支付页面,提示用户某些商品的库存不足,请重新选购
if(no){
logger.warn("某些商品库存不足!请重新选购!");
return "redirect:/order/confirmOrder.html";
}
// if(!no){
// //如果检查没有出现库存不足的情况,则进行砍库存操作
// for (int i = 0; i < cartInfo.getProductList().size(); i++) {
// Product product = cartInfo.getProductList().get(i);
// ProductStockInfo stockInfo = SystemManager.productStockMap.get(product.getId());
// stockInfo.setStock(stockInfo.getStock() - product.getBuyCount());
// stockInfo.setChangeStock(true);
// SystemManager.productStockMap.put(product.getId(),stockInfo);
// }
// }
// }
//获取配送方式
Express express = SystemManager.getInstance().getExpressMap().get(e.getExpressCode());
if(express==null){
throw new NullPointerException("没有编码为"+e.getExpressCode()+"的配送方式!本次请求视为非法!");
}
//创建订单对象
Order order = new Order();
order.setAccount(account.getAccount());
}
ordershipService.update(e.getOrdership());
return "redirect:toEdit?id=" + e.getId();
}
/**
* 根据省份编码获取城市列表
*
* @return
* @throws IOException
*/
@RequestMapping(value = "selectCitysByProvinceCode")
@ResponseBody
public String selectCitysByProvinceCode() throws IOException {
logger.error("selectCitysByProvinceCode...");
String provinceCode = RequestHolder.getRequest().getParameter("provinceCode");
logger.error("selectCitysByProvinceCode...provinceCode=" + provinceCode);
if (StringUtils.isBlank(provinceCode)) {
throw new NullPointerException("provinceCode is null");
}
// Area area = new Area();
// area.setCode(provinceCode);
Map<String, Area> areaMap = SystemManager.getInstance().getAreaMap();
if (areaMap != null && areaMap.size() > 0) {
net.jeeshop.services.front.area.bean.Area areaInfo = areaMap.get(provinceCode);
logger.error("areaInfo = " + areaInfo);
if (areaInfo != null && areaInfo.getChildren() != null && areaInfo.getChildren().size() > 0) {
String jsonStr = JSON.toJSONString(areaInfo.getChildren());
logger.error("jsonStr=" + jsonStr);
return (jsonStr);
}
}
return "{}";
}
/**
* 根据城市编码获取区域列表
*
* @return
* @throws IOException
*/
@RequestMapping(value = "selectAreaListByCityCode")
@ResponseBody
public String selectAreaListByCityCode() throws IOException {
logger.error("selectAreaListByCityCode...");
String provinceCode = RequestHolder.getRequest().getParameter("provinceCode");
String cityCode = RequestHolder.getRequest().getParameter("cityCode");
*/
// public String buy(){
// String id = getRequest().getParameter("#request.goodsDetail.id");
// System.out.println("id="+id);
// getE().clear();
// getE().setId(id);
// Product goods = productService.selectOne(getE());
//
// List<Product> goodsList = (List<Product>) getSession().getAttribute(WebGlobal.myCart);
// if(goodsList==null){
// goodsList = new LinkedList<Product>();
// }
// goodsList.add(goods);
// getSession().setAttribute(WebGlobal.myCart, goodsList);
// return "toCart";
// }
/**
* 门户加载指定页面的产品、以及公共的产品目录
* @return
*/
// public String list(){
// getSession().setAttribute("selectMenu", menuID);
//
// //加载指定菜单关联的目录下的产品列表
// IndexMenu indexMenu = new IndexMenu();
// indexMenu.setId(menuID);
// IndexMenu menu = indexmenuService.selectOne(indexMenu);
// e.setSuperTypeID(menu.getCatalogID());
// productService.selectList(e);
// return "list";
// }
/**
* 获取新闻列表
* @return
* @throws Exception
*/
@RequestMapping("newsList")
public String newsList(ModelMap model, @ModelAttribute("e")News news) throws Exception{
News newsInfo = new News();
newsInfo.setType(News.news_type_notice);
e.setCatalogID(catalog);
//加载指定类别下商品属性和参数
changeCatalog(e, true);
// return page_toAdd;
}else{
throw new NullPointerException("请求非法!");
}
}
List<Gift> giftList = loadGiftList();
model.addAttribute("giftList", giftList);
return page_toAdd;
}
/**
* 加载商品赠品列表
*/
private List<Gift> loadGiftList(){
Gift gift = new Gift();
gift.setStatus(Gift.gift_status_up);
List<Gift> giftList = giftService.selectList(gift);
return giftList;
}
//列表页面点击 编辑商品
@Override
public String toEdit(@ModelAttribute("e")Product e, ModelMap model) throws Exception {
// getSession().setAttribute("insertOrUpdateMsg", "");
return toEdit0(e, model);
}
/**
* 修改商品的类别,会联动清除商品已有的属性和参数
* @return
* @throws Exception
*/
@RequestMapping(value = "updateProductCatalog", method = RequestMethod.POST)
public String updateProductCatalog(Product e, ModelMap model) throws Exception {
public OrderService getService() {
return orderService;
}
public void setOrderService(OrderService orderService) {
this.orderService = orderService;
}
@Override
protected void selectListAfter(PagerModel pager) {
super.selectListAfter(pager);
if (pager.getList() != null) {
// 订单状态中文化显示。
for (int i = 0; i < pager.getList().size(); i++) {
Order item = (Order) pager.getList().get(i);
item.setStatusStr(KeyValueHelper.get("order_status_" + item.getStatus()));
item.setPaystatusStr(KeyValueHelper.get("order_paystatus_" + item.getPaystatus()));
}
}
}
/**
* 退款管理、退货管理 页面必须直接显示与退款、退款状态相一致的数据
*/
@Override
protected void setParamWhenInitQuery(Order e) {
String refundStatus = RequestHolder.getRequest().getParameter("refundStatus");
String status = RequestHolder.getRequest().getParameter("status");
String paystatus = RequestHolder.getRequest().getParameter("paystatus");
// String notCancel = getRequest().getParameter("notCancel");
logger.error("refundStatus=" + refundStatus + ",status=" + status + ",paystatus=" + paystatus);
if (StringUtils.isNotBlank(refundStatus)) {
e.setRefundStatus(refundStatus);
}
if (StringUtils.isNotBlank(status)) {
e.setStatus(status);
}
if (StringUtils.isNotBlank(paystatus)) {
e.setPaystatus(paystatus);
}
}
/**
* 后台用户管理
*
*/
@Controller
@RequestMapping("/manage/user")
public class UserAction extends BaseController<User> {
private static final org.slf4j.Logger logger = LoggerFactory.getLogger(UserAction.class);
private static final long serialVersionUID = 1L;
private static final String page_input = "/manage/system/login";
private static final String page_register = "/manage/system/user/registerUser";
private static final String page_home = "/manage/system/home";
private static final String page_toList = "/manage/system/user/userList";
private static final String page_toAdd = "/manage/system/user/editUser";
private static final String page_toEdit = "/manage/system/user/editUser";
private static final String page_toChangePwd = "/manage/system/user/toChangePwd";
private static final String page_changePwd_result = "/manage/system/user/changePwd";
private static final String page_show = "/manage/system/user/show";
private static final String page_initManageIndex = page_home;
public UserAction() {
super.page_toEdit = page_toEdit;
super.page_toList = page_toList;
super.page_toAdd = page_toAdd;
}
@Autowired
private UserService userService;
@Autowired
private RoleService roleService;
@Autowired
private MenuService menuService;
@Resource(name = "systemlogServiceManage")
private SystemlogService systemlogService;
}
public ManageCache getManageCache() {
return manageCache;
}
public void setManageCache(ManageCache manageCache) {
this.manageCache = manageCache;
}
public void setRoleService(RoleService roleService) {
this.roleService = roleService;
}
@Override
public void insertAfter(User e) {
e.clear();
}
public void setSystemlogService(SystemlogService systemlogService) {
this.systemlogService = systemlogService;
}
@RequestMapping("loadData")
@ResponseBody
@Override
public PagerModel loadData(HttpServletRequest request, User e){
int offset = 0;
int pageSize = 10;
if (request.getParameter("start") != null) {
offset = Integer
.parseInt(request.getParameter("start"));
}
if (request.getParameter("length") != null) {
pageSize = Integer
.parseInt(request.getParameter("length"));
}
if (offset < 0)
offset = 0;
if(pageSize < 0){
pageSize = 10;
}
e.setOffset(offset);
e.setPageSize(pageSize);
PagerModel pager = userService.selectPageList(e);
pager.setRecordsTotal(pager.getTotal());
pager.setRecordsFiltered(pager.getTotal());
return pager;
}
@RequestMapping(value = "login", method = RequestMethod.GET)
public String login(@ModelAttribute("e") User e, HttpSession session){
public String update(HttpServletRequest request, @ModelAttribute("e") E e, RedirectAttributes flushAttrs) throws Exception {
// User user = (User) getSession().getAttribute(Global.USER_INFO);
// if(user==null){
// throw new NullPointerException();
// }
// if(user.getDbPrivilegeMap()!=null && user.getDbPrivilegeMap().size()>0){
// if(user.getDbPrivilegeMap().get(Container.db_privilege_update)==null){
// throw new PrivilegeException(Container.db_privilege_update_error);
// }
// }
getService().update(e);
insertAfter(e);
addMessage(flushAttrs, "操作成功!");
return "redirect:selectList";
}
/**
* insert之后,selectList之前执行的动作,一般需要清除添加的E,否则查询会按照E的条件进行查询.
* 部分情况下需要保留某些字段,可以选择不清除
*
* @param e
*/
protected void insertAfter(E e){
}
/**
* 公共的插入数据方法,子类可以通过重写此方法实现个性化的需求。
*
* @return
* @throws Exception
*/
@RequestMapping(value = "insert",method = RequestMethod.POST)
public String insert(HttpServletRequest request, @ModelAttribute("e") E e, RedirectAttributes flushAttrs) throws Exception {
// User user = (User) getSession().getAttribute(Global.USER_INFO);
// if(user==null){
// throw new NullPointerException();
// }
// if(user.getDbPrivilegeMap()!=null && user.getDbPrivilegeMap().size()>0){
// if(user.getDbPrivilegeMap().get(Container.db_privilege_insert)==null){
// throw new PrivilegeException(Container.db_privilege_insert_error);
// }
// }
/**
* 设置订单为已归档
*
* @return
* @throws IOException
*/
// public String setFile() throws IOException{
// if(StringUtils.isBlank(e.getId())){
// throw new NullPointerException();
// }
//
// Order order = new Order();
// order.setStatus(Order.order_status_file);
// order.setId(e.getId());
// orderService.update(order);
//
// insertOrderlog(e.getId(),"【已归档】");
//
// toEdit2();
// return null;
// }
/**
* 修改订单的各种状态
*
* @return
* @throws Exception
*/
// @Deprecated
// public String changeOrderStatus() throws Exception {
// logger.error(">>>changeOrderStatus...");
String aaa = getRequest().getParameter("aaa");
log.error(">>>changeOrderStatus...aaa="+this.aaa);
// return null;
// }
/**
* 后台修改订单总金额
*
* @return
* @throws Exception
*/
@RequestMapping(value = "updatePayMonery", method = RequestMethod.POST)
*
*
*/
@Controller("frontProductAction")
@RequestMapping("product")
public class ProductAction extends FrontBaseController<Product> {
private static final long serialVersionUID = 1L;
private static final org.slf4j.Logger logger = LoggerFactory.getLogger(ProductAction.class);
@Autowired
private ProductService productService;//商品服务
@Autowired
private CommentService commentService;//评论服务
@Autowired
private AddressService addressService;//收货人地址服务
@Autowired
private Attribute_linkService attribute_linkService;//商品属性链接表服务
@Autowired
private NewsService newsService;//文章服务
@Autowired
private FavoriteService favoriteService;//商品收藏夹服务
@Autowired
private EmailNotifyProductService emailNotifyProductService;//商品到货通知
@Autowired
private SpecService specService;
@Autowired
private GiftService giftService;
// private int catalogID;//选择的产品目录ID
// private String catalogCode;//选择的目录code
// private int attributeID;//产品属性ID
// private String special;//促销活动
// private Map<String, String> orderMap;//排序map
// private List<Product> productList;//商品列表
// private int orderBy;//排序规则
@Override
public ProductService getService() {
return productService;
}
@ModelAttribute("catalogCode")
public String getCatalogCode(){
String catalogCode = RequestHolder.getRequest().getParameter("catalogCode");
if(StringUtils.isBlank(catalogCode)){
String attributeID = RequestHolder.getRequest().getParameter("attrID");
Attribute attr;
if(StringUtils.isNotBlank(attributeID) && (attr=SystemManager.getInstance().getAttrsMap().get(StringUtils.trim(attributeID)))!=null) {
catalogCode = SystemManager.getInstance().getCatalogsMap().get(String.valueOf(attr.getCatalogID())).getCode();
// .getResourceAsStream("/code.properties"), "utf-8")));
logger.info(p.toString());
// log.info(code.toString());
} catch (IOException e) {
e.printStackTrace();
}
manageExpressMap.put("shunfeng", "顺风快递");
manageExpressMap.put("ems", "EMS");
manageExpressMap.put("shentong", "申通E物流");
manageExpressMap.put("yuantong", "圆通速递");
manageExpressMap.put("zhongtong", "中通速递");
manageExpressMap.put("zhaijisong", "宅急送");
manageExpressMap.put("yunda", "韵达快运");
manageExpressMap.put("tiantian", "天天快递");
manageExpressMap.put("lianbangkuaidi", "联邦快递");
manageExpressMap.put("huitongkuaidi", "汇通快运");
}
public String getProperty(String key){
return p.getProperty(key);
}
private Random random = new Random();
/**
* 随机从图集里面选取一张图片
* @return
*/
public String getImageRandom(){
SystemSetting systemSetting = getSystemSetting();
if(systemSetting==null || systemSetting.getImagesList()==null || systemSetting.getImagesList().size()==0){
logger.error("系统未设置图集,但广告位却设置了图集优先显示。请管理员立刻设置图集。");
return null;
}
int n = random.nextInt(systemSetting.getImagesList().size());
return systemSetting.getImageRootPath()+systemSetting.getImagesList().get(n);
}
/**
* 获取网站上下文路径/house
* 正式环境和测试环境获取上下文不一样
* @param request
* @return
*/
/**
* 系统设置
*/
@Controller
@RequestMapping("/manage/systemSetting/")
public class SystemSettingAction extends BaseController<SystemSetting> {
private static final Logger logger = LoggerFactory.getLogger(SystemSetting.class);
private static final long serialVersionUID = 1L;
@Autowired
private SystemSettingService systemSettingService;
@Autowired
private FrontCache frontCache;
SystemSettingAction(){
super.page_toList = null;// not support
super.page_toAdd = null;// not support
super.page_toEdit = "/manage/systemSetting/systemSettingEdit";
}
// private String sync;//是否立即同步的标志
public FrontCache getFrontCache() {
return frontCache;
}
public void setFrontCache(FrontCache frontCache) {
this.frontCache = frontCache;
}
@Override
public SystemSettingService getService() {
return systemSettingService;
}
@Override
protected void selectListAfter(PagerModel pager) {
pager.setPagerUrl("selectList");
}
public void setSystemSettingService(
SystemSettingService systemSettingService) {
this.systemSettingService = systemSettingService;
}
// public String buyNow(){
// logger.error("buyNow...");
// return "confirmOrder";
// }
/**
* 直接购买,添加到购物车
* @return
* @deprecated
*/
// public String buy(){
// String id = getRequest().getParameter("#request.goodsDetail.id");
// System.out.println("id="+id);
// getE().clear();
// getE().setId(id);
// Product goods = productService.selectOne(getE());
//
// List<Product> goodsList = (List<Product>) getSession().getAttribute(WebGlobal.myCart);
// if(goodsList==null){
// goodsList = new LinkedList<Product>();
// }
// goodsList.add(goods);
// getSession().setAttribute(WebGlobal.myCart, goodsList);
// return "toCart";
// }
/**
* 门户加载指定页面的产品、以及公共的产品目录
* @return
*/
// public String list(){
// getSession().setAttribute("selectMenu", menuID);
//
// //加载指定菜单关联的目录下的产品列表
// IndexMenu indexMenu = new IndexMenu();
// indexMenu.setId(menuID);
// IndexMenu menu = indexmenuService.selectOne(indexMenu);
// e.setSuperTypeID(menu.getCatalogID());
// productService.selectList(e);
// return "list";
// }
/**
* 获取新闻列表
* @return
* @throws Exception
*/
} else if (!((Boolean)hashA.get("is_dir")) && ((Boolean)hashB.get("is_dir"))) {
return 1;
} else {
return ((String)hashA.get("filetype")).compareTo((String)hashB.get("filetype"));
}
}
}
}
package net.jeeshop.web.action.manage.system;
/**
* 资源管理
*
*/
@Controller
@RequestMapping("/manage/menu/")
public class MenuAction extends BaseController<Menu> {
private static final long serialVersionUID = 1L;
hash.put("is_photo", false);
hash.put("filetype", "");
} else if (file.isFile()) {
String fileExt = fileName.substring(fileName.lastIndexOf(".") + 1).toLowerCase();
String _fileName = fileName.substring(0, fileName.lastIndexOf("."));
//String fileNameA = _fileName.split("_")[1];
//logger.debug("fileNameA="+fileNameA);
/* if(fileNameA.equals("1") || fileNameA.equals("2")){
//if(addFileMap.get(fileNameA)!=null){
continue;
} */
//addFileMap.put(fileNameA, fileNameA);
hash.put("is_dir", false);
hash.put("has_file", false);
hash.put("filesize", file.length());
hash.put("is_photo", Arrays.<String>asList(fileTypes).contains(fileExt));
hash.put("filetype", fileExt);
}
hash.put("filename", fileName);
hash.put("datetime", new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(file.lastModified()));
fileList.add(hash);
}
}
if ("size".equals(order)) {
Collections.sort(fileList, new SizeComparator());
} else if ("type".equals(order)) {
Collections.sort(fileList, new TypeComparator());
} else {
Collections.sort(fileList, new NameComparator());
}
JSONObject result = new JSONObject();
result.put("moveup_dir_path", moveupDirPath);
result.put("current_dir_path", currentDirPath);
result.put("current_url", currentUrl);
result.put("total_count", fileList.size());
result.put("file_list", fileList);
logger.debug("json=" + result.toString());
return (result.toString());
}
public class NameComparator implements Comparator {
Collection<MenuItem> userMenus = loadMenus(u);
session.setAttribute("userMenus", userMenus);
try {
loginLog(u,"login");
} catch (Exception ex) {
ex.printStackTrace();
}
return "redirect:/manage/user/home";
}
private Collection<MenuItem> loadMenus(User u) {
/*
* 首先,加载顶级目录或页面菜单
*/
Map<String, String> param = new HashMap<String, String>();
if (u != null && u.getRid() != null) {
param.put("rid", u.getRid());//角色ID
}
// param.put("pid", pid);//菜单父ID
List<Menu> menus = menuService.selectList(param);
//创建菜单集合
LinkedHashMap<String, MenuItem> root = new LinkedHashMap<String, MenuItem>();
//循环添加菜单到菜单集合
for (Menu menu : menus) {
MenuItem item = new MenuItem(menu.getName(), null);
item.setId(menu.getId());
item.setPid(menu.getPid());
item.setMenuType(menu);
// if(item.getType().equals(MenuType.page)){
// item.setIcon("http://127.0.0.1:8082/myshop/resource/images/letter.gif");
// }
item.setUrl(StringUtils.trimToEmpty(menu.getUrl()));
if(item.isRootMenu()) {
root.put(item.getId(), item);
}
}
for (Menu menu : menus) {
MenuItem item = new MenuItem(menu.getName(), null);
item.setId(menu.getId());
item.setPid(menu.getPid());
public void setAreaMap(Map<String, Area> areaMap) {
putCacheObject("areaMap", (Serializable)areaMap);
}
/**
* 前台订单支付页面--物流列表
* @return
*/
public Map<String, Express> getExpressMap() {
return getCacheObject("expressMap");
}
public void setExpressMap(Map<String, Express> expressMap) {
// this.expressMap = expressMap;
putCacheObject("expressMap", (Serializable)(expressMap));
}
/**
* 广告列表
* @return
*/
public Map<String, Advert> getAdvertMap() {
// return advertMap;
return getCacheObject("advertMap");
}
public void setAdvertMap(Map<String, Advert> advertMap) {
// this.advertMap = advertMap;
putCacheObject("advertMap", (Serializable)advertMap);
}
/**
* 后台发货页面物流公司列表
* @return
*/
public Map<String, String> getManageExpressMap() {
// return manageExpressMap;
Map<String,String> cachedMap = getCacheObject("manageExpressMap");
if(cachedMap != null){
return cachedMap;
}
return SystemManager.manageExpressMap;
}
public void setManageExpressMap(Map<String, String> manageExpressMap) {
putCacheObject("manageExpressMap", Lists.newArrayList(manageExpressMap));
}
/**