Commit 1df51eee by wnb0128

第一次上传商城项目--think.wang

0 parents
Showing 1000 changed files with 3648 additions and 0 deletions

Too many changes to show.

To preserve performance only 1000 of 1000+ files are displayed.

*.iml
**/target
**/node_modules
**/test.sql
.idea
package-lock.json
**/dist
.classpath
.factorypath
.vscode
.settings
.project
application-wt1hd.properties
application-demo.properties
import_waitan.sql
MIT License
Copyright (c) 2019 microapp
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
# 前言
[![Spring Boot](https://img.shields.io/badge/spring--boot-2.1.1.1.RELEASE-brightgreen)](https://github.com/spring-projects/spring-boot)
[![vue](https://img.shields.io/badge/vue-2.6.10-brightgreen.svg)](https://github.com/vuejs/vue)
[![element-ui](https://img.shields.io/badge/element--ui-2.11.0-brightgreen.svg)](https://github.com/ElemeFE/element)
[![Vant](https://img.shields.io/badge/vant-2.2.0-brightgreen.svg)](https://youzan.github.io/vant/#/zh-CN/intro)
[![Vant-weapp](https://img.shields.io/badge/vant--weapp-1.0.1-brightgreen)](https://youzan.github.io/vant-weapp/#/intro)
[![Flutter](https://img.shields.io/badge/Flutter-1.9.6-brightgreen)](https://flutter.dev/)
[![license](https://img.shields.io/github/license/mashape/apistatus.svg)](https://github.com/enilu/linjiashop/blob/master/LICENSE)
[![Gitee stars](https://gitee.com/microapp/linjiashop/badge/star.svg?theme=social)](https://gitee.com/microapp/linjiashop)
[![GitHub stars](https://img.shields.io/github/stars/microapp-store/linjiashop.svg?style=social&label=Stars)](https://github.com/microapp-store/linjiashop)
- linjiashop 是一个基于[Spring Boot](https://spring.io/projects/spring-boot/)和[Vue.js](https://cn.vuejs.org)的web商城系统
- linjiashop 包含了商城的后台管理系统,手机h5,小程序版本
- linjiashop 包含了app版本(基于flutter) 仓库地址[gitee](https://gitee.com/microapp/linjiashop-flutter),[github](https://github.com/microapp-store/linjiashop-flutter)
- linjiashop 包含了uniapp版本(基于uniapp通过一套代码实现H5,Android,IOS,小程序等多平台 [项目地址](http://microapp.gitee.io/linjiashop/ecosystem/uniapp.html)
- linjiashop 采用[web-flash](http://enilu.gitee.io/web-flash/)作为底层基础框架搭建,开发过程遇到问题请多阅读该项目文档。
## 演示
### 演示环境
- 用户端H5:[http://linjiashop.microapp.store](http://linjiashop.microapp.store) 演示账号/密码:15011112222/admin
- 用户端H5(基于uniapp)[http://linjiashop-uni.microapp.store/](http://linjiashop-uni.microapp.store/)
- App(基于uniapp)[http://fir.microapp.store/linjiashop](http://fir.microapp.store/linjiashop)
- 后台管理:[http://linjiashop-admin.microapp.store](http://linjiashop-admin.microapp.store) 管理员账号/密码:admin/admin
## 真实环境,支持下单支付
- 公众号演示:关注公众号“外滩一号店"进行体验,或者扫描下面二维码关注
![外滩一号店](https://gitee.com/microapp/linjiashop/raw/master/doc/img/online/wt1hd.jpg)
## 功能模块
linjiashop包含了后台管理功能和手机端商城业务功能
- 基础模块
- 部门管理
- 用户管理
- 角色管理
- 菜单管理
- 权限分配
- 参数管理
- 数据字典管理
- 定时任务管理
- 操作日志
- 登录日志
- cms内容管理
- 消息管理:配置消息模板,发送短信,邮件消息
- 基于idea插件的代码生成
- 商城功能
- 会员管理
- 商品类别
- 商品管理
- 订单管理
- 购物车
- banner管理
- 收藏列表
- 手机端
-完整的商城购物功能
## 运行效果图
_商品素材取自小米商城_
### 手机端H5
![手机端](doc/guide/img/mobile.gif)
### IOS
<table>
<tr>
<td>
<img src="doc/img/app/home.png" width="300"/></td>
<td>
<img src="doc/img/app/find.png" width="300"/></td>
</tr>
<tr>
<td>
<img src="doc/img/app/guige.jpg" width="300"/></td>
<td>
<img src="doc/img/app/login.png" width="300"/></td>
</tr>
<tr>
<td>
<img src="doc/img/app/mine.png" width="300"/></td>
<td>
<img src="doc/img/app/cart.png" width="300"/></td>
</tr>
</table>
### Android
![效果](doc/img/app/mobile.gif)
### 后台管理
![后台管理](doc/guide/img/admin.gif)
## 技术选型
- 核心框架:Spring Boot
- 数据库层:Spring data jpa
- 数据库连接池:Druid
- 缓存:Ehcache
- 前端:后台管理基于[element](http://element-cn.eleme.io),手机端界面基于[vant](https://youzan.github.io/vant/#/zh-CN/intro)
## 目录说明
- linjiashop-admin PC端后台管理的前端网页
- linjiashop-admin-api PC端后台管理的api服务
- linjiashop-mobile 手机商城的前端网页
- linjiashop-mobile-api 移动端商城的api服务(h5,小程序,app都用改api服务作为后台接口)
- linjiasho-wxapp 微信小程序商城
- linjiashop-core 基础模块,包括工具类,dao,service,bean等内容
- linjiashop-generator 代码生成模块,根据实体生成dao,service,后台管理的controller和页面,配合IDEA 代码生成插件[webflash-generator](https://plugins.jetbrains.com/plugin/12648-webflash-generator)使用效果更好,使用前请仔细阅读该[文档](http://enilu.gitee.io/web-flash/ecosystem/code-generator.html)
## 快速开始
- 克隆本项目
- 导入idea或者eclipse
- 确保开发工具下载并安装了lombok插件,另外由于lombok有版本差异,如果出现问题,可以更新maven以来中lombok的版本来解决
- 创建数据库:linjiashop
```sql
CREATE DATABASE IF NOT EXISTS linjiashop DEFAULT CHARSET utf8 COLLATE utf8_general_ci;
CREATE USER 'linjiashop'@'%' IDENTIFIED BY 'linjiashop191028';
GRANT ALL privileges ON linjiashop.* TO 'linjiashop'@'%';
flush privileges;
```
- 下载项目测试数据的图片:链接:[https://pan.baidu.com/s/1V1QTSLspuDRuwI7H9TjcOA](https://pan.baidu.com/s/1V1QTSLspuDRuwI7H9TjcOA) 提取码:dyj6 ,将图片存放到t_sys_cfg表中system.file.upload.path配置的目录下(注意该目录为绝对路径,该目录可以通过“系统管理”-“参数管理”进行配置)
- 启动后台管理
- 启动后台管理api服务:linjiashop-admin-api
- 修改linjiashop-admin-api中数据库连接配置
```properties
## 首次启动需要设置下列配置项设置为create,以便系统可以自动创建表并导入./import.sql测试数据文件
## 如果下面配置无法自动建表并导入测试数据文件;则可以手动初始化数据库,手动使用的初始化文件文件位于:doc/database.sql
spring.jpa.hibernate.ddl-auto=create
```
- 启动linjiashop-admin-api主类:cn.enilu.flash.api.AdminApiApplication,访问http://localhost:8082/swagger-ui.html , 保证api服务启动成功
- 启动后台管理的前端界面:linjiashop-admin
- 运行 npm install --registry=https://registry.npm.taobao.org
- 运行npm run dev
- 启动成功后访问 http://localhost:9528 ,登录,用户名密码:admin/admin
- 启动手机端商城
- 启动手商城的api服务:linjiashop-mobile-api
- 修改linjiashop-mobile-api中数据库连接欸配置
- 启动linjiashop-mobile-api主类:cn.enilu.flash.MobileApiApplication,访问http://localhost:8081/swagger-ui.html , 保证api服务启动成功
- 启动手机商城的前端:linjiashop-mobile
- 运行 npm install --registry=https://registry.npm.taobao.org
- 运行npm run dev
- 启动成功后访问 http://localhost:8080/#/index
- 微信小程序开发
- 首先启动后台api服务,和h5公用一个后台服务,即:linjiashop-mobile-api
- 进入linjiashop-wxapp目录
- 运行 npm install --registry=https://registry.npm.taobao.org
- 运行npm run dev
- 启动微信开发工具导入linjiashop-wxapp/dist/wx 目录即可预览小程序
## 技术交流
- 关注公众号:嗨客帝国,点击对应的项目菜单进群交流。
![公众号二维码](doc/guide/img/haike.jpg)
- 论坛提问:
[http://bbs.enilu.cn](http://bbs.enilu.cn)
## 在线文档
- 项目文档:[http://microapp.gitee.io/linjiashop](http://microapp.gitee.io/linjiashop/)
- 该项目克隆并扩展自[web-flash](https://github.com/enilu/web-flash),所以开发的时候多看看web-flash的[在线文档](http://enilu.gitee.io/web-flash)
- 该项目手机端linjiashop-mobile使用有赞Vant组件库,开发过程可以参考Vant的[在线文档](https://youzan.github.io/vant/#/zh-CN/intro)
- 该项目微信小程序使用mpvue+vant-weapp,开发过程请参考相关文档:[mpvue文档](http://mpvue.com/),[vant-weapp文档](https://youzan.github.io/vant-weapp/#/intro)
- 该项目的业务功能和部分功能代码参考复用了[litemall](https://github.com/linlinjava/litemall),感谢[linlinjava](https://github.com/linlinjava)
- [视频教程](http://microapp.gitee.io/linjiashop/other/video.html)
module.exports = {
title: '邻家小铺',
description: '使用邻家小铺搭建自己的全平台商城系统',
base: '/linjiashop/',
head: [
['link', { rel: 'shortcut icon', type: "image/x-icon", href: './favicon.ico' }],
['script',{},`
var _hmt = _hmt || [];
(function() {
var hm = document.createElement("script");
hm.src = "https://hm.baidu.com/hm.js?9d53390a6ba903e20fabf2e207b3e9bb";
var s = document.getElementsByTagName("script")[0];
s.parentNode.insertBefore(hm, s);
})();
`
]
],
evergreen: true,
editLinkText:'在 GitHub 上编辑此页',
port: 8090,
ga: 'UA-71886989-13',
themeConfig: {
repo: 'microapp-store/linjiashop',
docsDir: 'doc',
editLinks: true,
editLinkText: '编辑此页面!',
nav: [
{text: '指南', link: '/guide/base/preface'},
{text: '生态系统',
items:[
{text:"项目",items:[
{text:'linjiashop-flutter(app)',link:'/ecosystem/app'},
{text:'linjiashop-uniapp',link:'/ecosystem/uniapp'},
{text:'web-flash',link:'http://enilu.gitee.io/web-flash'},
{text:'code-generator',link:'http://enilu.gitee.io/web-flash/ecosystem/code-generator.html'},
{text:'database-doc-generator',link:'http://enilu.gitee.io/web-flash/ecosystem/database-doc-generator.html'},
{text:'material-admin',link:'https://enilu.gitee.io/material-admin'}
]
},
{text:'帮助',items:[
{text: '在线资源',link:'/guide/base/resource'},
{text:'问答社区',link:'/guide/other/xiaomiquan'},
{text:'视频教程',link:'/guide/other/video'},
{text:'QQ群(254059156)',link:'https://jq.qq.com/?_wv=1027&k=5rEmcb6'},
{text:'作者blog',link:'http://blog.enilu.cn'},
{text:'FAQ',link:'/guide/other/faq'},
{text:'Change Log',link:'/guide/other/changelog'}
]},
]
},
{text: '上线实战', link: '/online/summary'},
{text: '捐赠',link:'/donate'},
{text: 'Gitee', link: 'https://gitee.com/microapp/linjiashop'}
],
sidebar: {
'/guide/':[
{
title: '准备',
collapsable: false,
children: [
'/guide/base/preface',
'/guide/base/jdkAndMaven',
'/guide/base/modules'
]
},
{
title: '快速开始',
collapsable: false,
children: [
'/guide/quickstart/quickstart',
'/guide/quickstart/clone',
'/guide/quickstart/initDb',
'/guide/quickstart/config',
'/guide/quickstart/startup'
]
},
{
title: '二次开发',
collapsable: false,
children: [
'/guide/develop/develop',
'/guide/develop/api',
'/guide/develop/banner',
'/guide/develop/attribute',
'/guide/develop/wechat'
]
}, {
title: '其他',
collapsable: false,
children:[
'/guide/other/faq',
'/guide/other/changelog'
]
}
],'/online/':[
{
title: '上线实战',
collapsable: false,
children: [
'/online/summary',
'/online/day01',
'/online/day02',
'/online/day04',
'/online/day05',
'/online/day06'
]
}
],'/ecosystem/':[
{
title:'生态系统',
collapsable: false,
children: [
'/ecosystem/app',
'/ecosystem/uniapp'
]
}]
}
}
}
No preview for this file type
.getting-started .outbound,
.nav-links .outbound {
display: none !important;
}
.getting-started a img {
margin-right: 8px !important;
}
.getting-started a img.no-margin {
margin-right: 0px !important;
}
//global
p code {
// color: #e96900!important;
// background-color: #f8f8f8!important;
// margin: 0 2px!important;
// padding: 0.25rem 0.4rem!important;
}
blockquote {
font-size: 15px !important;
color: #858585 !important;
border-left: 0.25rem solid #42b983 !important;
font-weight: 1000 !important;
}
---
home: true
heroImage: /logo.jpg
heroText: ''
actionText: 快速开始 →
actionLink: /guide/base/preface
footer: MIT Licensed | Copyright © 2019-present microapp.store
---
<div style="text-align: center">
<Bit/>
</div>
<div class="features">
<div class="feature">
<h2>简单快捷</h2>
<p>基于spring boot,vuejs,futter快速构建全平台商城系统</p>
</div>
<div class="feature">
<h2>支持齐全</h2>
<p>提供api,后台管理,包含h5,微信小程序,android,ios应用程序完整方案。</p>
</div>
<div class="feature">
<h2>最新技术栈</h2>
<p>使用Spring Boot2+JPA构建后端服务,<br>vue/element/vux/flutter构建前端界面</p>
</div>
</div>
This diff could not be displayed because it is too large.
::: tip Donate
如果你觉得这个项目帮助到了你,你可以帮作者买一杯果汁表示鼓励
:::
<img src="./img/donate.jpg" width = "400" align=center />
# linjiasho-flutter
- 基于fluetter开发的linjiashop app版本,使用flutter 1.12.13(后续会更新,以项目readme为准) 版本构建
- 仓库地址[gitee](https://gitee.com/microapp/linjiashop-flutter),[github](https://github.com/microapp-store/linjiashop-flutter)
## 技术选型
- 核心框架:flutter
- 数据存储:shared_preferences
- 屏幕适配:flutter_screenutil
- 路由管理:fluro
- 顶部状态栏:flutter_statusbarcolor
- 网络请求:dio
- 事件广播:event_bus
- 刷新控件:flutter_easyrefresh
- 左滑删除:flutter_slidable
- toast:fluttertoast
- 拨打客服电话:url_launcher
## 运行效果图
- **IOS**:
<table>
<tr>
<td>
<img src="../img/app/home.png" width="300"/></td>
<td>
<img src="../img/app/find.png" width="300"/></td>
</tr>
<tr>
<td>
<img src="../img/app/guige.jpg" width="300"/></td>
<td>
<img src="../img/app/login.png" width="300"/></td>
</tr>
<tr>
<td>
<img src="../img/app/mine.png" width="300"/></td>
<td>
<img src="../img/app/cart.png" width="300"/></td>
</tr>
</table>
- **Android**:
![效果](../img/app/mobile.gif)
- **下载二维码(Android)**:
![二维码](../img/app/code.png)
- 测试账号:15011112222 admin
# linjiashop-uniapp
## 前言
- linjiashop-uniapp,是[邻家小铺](http://microapp.gitee.io/linjiashop/)的uniapp版本,通过uniapp技术达到一套代码覆盖全平台(H5,Android,IOS,微信小程序,其他如支付宝,qq,头条小程序也可以通过简单的适配实现)的目的
- 项目地址[gitee](https://gitee.com/microapp/linjiashop-uniapp),[github](https://github.com/microapp-store/linjiashop-uniapp)
- [官方文档:http://microapp.gitee.io/linjiashop/](http://microapp.gitee.io/linjiashop/ecosystem/uniapp.html)
- [点击加群交流反馈:254059156](http://qm.qq.com/cgi-bin/qm/qr?k=EEHjlB4XyM-Kh2eMCbRPRoT38-V3au0T&authKey=NE856fZKPJLjtJTwOA1MlWWtcATVwT4e3zhjCOHeye8am2posApW%2Fw%3D%3D&group_code=254059156)
## 演示
- H5:[http://linjiashop-uni.microapp.store/](http://linjiashop-uni.microapp.store/) 浏览器打开后通过F12打开控制台使用手机模式查看
- App:[http://fir.microapp.store/linjiashop](http://fir.microapp.store/linjiashop)
- 微信小程序:请自己用微信开发工具预览
## 快速开始
- 克隆本项目 git clone https://gitee.com/microapp/linjiashop-uniapp.git
- 使用Hbuilder X 开发工具打开本项目进行开发(本项目开发使用开发工具的2.7.14版本,为避免出现不必要的问题,建议使用开发工具不要低于本版本)
- 具体开发过程请参考uniapp[官方文档](https://uniapp.dcloud.io/)和uView的[官方文档](https://www.uviewui.com/)
## 版权信息
本项目遵循[MIT](https://en.wikipedia.org/wiki/MIT_License)开源协议,意味着您无需支付任何费用,也无需授权,即可将linjiashop-uniapp应用到您的产品中。
# 开发前必读
本章介绍本书所需要的一些准备工作. 请确保把各部分的准备工作完成
本文档基于Intellij IDEA,Mysql,Maven,JDK8这四个基本工具,
当然你也可以用Eclipse开发工具。
**Jdk**
- 请选用当前最新的版本,根据平台选用X64或X86版本的JDK8,并妥善安装
- JDK最低版本要求1.8
**MySQL**
- [Mysql官网](https://dev.mysql.com/)
- [下载页面](https://dev.mysql.com/downloads/), 选用5.6以上系列的版本
- 妥善安装,并配置账号密码
**Intellij IDEA**
- [Intellij IDEA官网](https://www.jetbrains.com/idea/)
- [下载页面](https://www.jetbrains.com/idea/download/)
- 请自行下载安装合适版本的IDEA(或者eclipse)
**Lombok**
- Lombok是一个可以通过简单的注解形式来帮助我们简化消除一些必须有,但显得很臃肿的Java代码的工具,通过使用对应的注解,可以在编译源码的时候生成对应的方法。
- 本系统用通过给实体类增加@Data注解让给实体类自动生成setter,getter方法。
- 开发之前需要安装开发工具对应的Lombok插件
- 添加新的实体的时候要在类名上增加@Data注解。
**Maven**
-[下载页面](http://maven.apache.org/download.cgi)
**Tomcat**
-如果在tomcat中部署,要求至少Tomcat8及其以上版本
# 基本包结构
本节详细说明本项目的基本目录结构
## 邻家小铺项目模块
- linjiashop-admin PC端后台管理的前端网页
- linjiashop-admin-api PC端后台管理的api服务
- linjiashop-mobile 手机商城的前端网页
- linjiashop-mobile-api 移动端商城的api服务(h5,小程序,app都用改api服务作为后台接口)
- linjiasho-wxapp 微信小程序商城
- linjiashop-core 基础模块,包括工具类,dao,service,bean等内容
- linjiashop-generator 代码生成模块,根据实体生成dao,service,后台管理的controller和页面,配合IDEA 代码生成插件[webflash-generator](https://plugins.jetbrains.com/plugin/12648-webflash-generator)使用效果更好,使用前请仔细阅读该[文档](http://enilu.gitee.io/web-flash/ecosystem/code-generator.html)
- linjiashop-flutter 商城app版本;项目地址:(https://gitee.com/microapp/linjiashop-flutter)[https://gitee.com/microapp/linjiashop-flutter]
---
pageClass: getting-started
---
# 前言
[![Spring Boot](https://img.shields.io/badge/spring--boot-2.1.1.1.RELEASE-brightgreen)](https://github.com/spring-projects/spring-boot)
[![vue](https://img.shields.io/badge/vue-2.6.10-brightgreen.svg)](https://github.com/vuejs/vue)
[![element-ui](https://img.shields.io/badge/element--ui-2.11.0-brightgreen.svg)](https://github.com/ElemeFE/element)
[![Vant](https://img.shields.io/badge/vant-2.2.0-brightgreen.svg)](https://youzan.github.io/vant/#/zh-CN/intro)
[![Vant-weapp](https://img.shields.io/badge/vant--weapp-1.0.1-brightgreen)](https://youzan.github.io/vant-weapp/#/intro)
[![Flutter](https://img.shields.io/badge/Flutter-1.12.13-brightgreen)](https://flutter.dev/)
[![license](https://img.shields.io/github/license/mashape/apistatus.svg)](https://github.com/enilu/linjiashop/blob/master/LICENSE)
[![Gitee stars](https://gitee.com/microapp/linjiashop/badge/star.svg?theme=social)](https://gitee.com/microapp/linjiashop)
[![GitHub stars](https://img.shields.io/github/stars/microapp-store/linjiashop.svg?style=social&label=Stars)](https://github.com/microapp-store/linjiashop)
- linjiashop 是一个基于[Spring Boot](https://spring.io/projects/spring-boot/)和[Vue.js](https://cn.vuejs.org)的web商城系统
- linjiashop 包含了商城的后台管理系统,手机h5,小程序版本
- linjiashop 包含了app版本(基于flutter) 仓库地址[gitee](https://gitee.com/microapp/linjiashop-flutter),[github](https://github.com/microapp-store/linjiashop-flutter)
- linjiashop 包含了uniapp版本(基于uniapp通过一套代码实现H5,Android,IOS,小程序等多平台 [项目地址](http://microapp.gitee.io/linjiashop/ecosystem/uniapp.html)
- linjiashop 采用[web-flash](http://enilu.gitee.io/web-flash/)作为底层基础框架搭建,开发过程遇到问题请多阅读该项目文档,本文档重点对业务功能做介绍。
## 演示
### 演示环境
- 用户端H5:[http://linjiashop.microapp.store](http://linjiashop.microapp.store) 演示账号/密码:15011112222/admin
- 用户端H5(基于uniapp)[http://linjiashop-uni.microapp.store/](http://linjiashop-uni.microapp.store/)
- App(基于uniapp)[http://fir.microapp.store/linjiashop](http://fir.microapp.store/linjiashop)
- 后台管理:[http://linjiashop-admin.microapp.store](http://linjiashop-admin.microapp.store) 管理员账号/密码:admin/admin
## 真实环境,支持下单支付
- 公众号演示:关注公众号“外滩一号店"进行体验,或者扫描下面二维码关注
![外滩一号店](https://gitee.com/microapp/linjiashop/raw/master/doc/img/online/wt1hd.jpg)
- [开发教程视频](https://space.bilibili.com/525325274/channel/detail?cid=115895)
## 功能模块
linjiashop包含了后台管理功能和手机端商城业务功能
- 基础模块
- 部门管理
- 用户管理
- 角色管理
- 菜单管理
- 权限分配
- 参数管理
- 数据字典管理
- 定时任务管理
- 操作日志shi
- 登录日志
- cms内容管理
- 消息管理:配置消息模板,发送短信,邮件消息
- 基于idea插件的代码生成
- 商城功能
- 会员管理
- 商品类别
- 商品管理
- 订单管理
- 购物车
- banner管理
- 收藏列表
- 手机端
-完整的商城购物功能
## 运行效果图
### 手机端
![手机端](../img/mobile.gif)
### IOS
<table>
<tr>
<td>
<img src="../../img/app/home.png" width="300"/></td>
<td>
<img src="../../img/app/find.png" width="300"/></td>
</tr>
<tr>
<td>
<img src="../../img/app/guige.jpg" width="300"/></td>
<td>
<img src="../../img/app/login.png" width="300"/></td>
</tr>
<tr>
<td>
<img src="../../img/app/mine.png" width="300"/></td>
<td>
<img src="../../img/app/cart.png" width="300"/></td>
</tr>
</table>
### Android
![效果](../../img/app/mobile.gif)
### 后台管理
![后台管理](../img/admin.gif)
## 技术选型
- 核心框架:Spring Boot
- 数据库层:Spring data jpa
- 数据库连接池:Druid
- 缓存:Ehcache
- 前端:后台管理基于[element](http://element-cn.eleme.io),手机端界面基于[vant](https://youzan.github.io/vant/#/zh-CN/intro)
## 目录说明
- linjiashop-admin PC端后台管理的前端网页
- linjiashop-admin-api PC端后台管理的api服务
- linjiashop-mobile 手机商城的前端网页
- linjiashop-mobile-api 手机端商城的api服务
- linjiashop-core 基础模块,包括工具类,dao,service,bean等内容
- linjiashop-generator 代码生成模块,主要生成后台管理的前后端代码,配合IDEA 代码生成插件[webflash-generator](https://plugins.jetbrains.com/plugin/12648-webflash-generator)使用效果更好
## 快速开始
- 克隆本项目
- 导入idea或者eclipse
- 确保开发工具下载并安装了lombok插件,另外由于lombok有版本差异,如果出现问题,可以更新maven以来中lombok的版本来解决
- 创建数据库:linjiashop
```sql
CREATE DATABASE IF NOT EXISTS linjiashop DEFAULT CHARSET utf8 COLLATE utf8_general_ci;
CREATE USER 'linjiashop'@'%' IDENTIFIED BY 'linjiashop191028';
GRANT ALL privileges ON linjiashop.* TO 'linjiashop'@'%';
flush privileges;
```
- 下载项目测试数据的图片:链接:[https://pan.baidu.com/s/1V1QTSLspuDRuwI7H9TjcOA](https://pan.baidu.com/s/1V1QTSLspuDRuwI7H9TjcOA) 提取码:dyj6 ,将图片存放到t_sys_cfg表中system.file.upload.path配置的目录下(注意该目录为绝对路径,该目录可以通过“系统管理”-“参数管理”进行配置)
- 启动后台管理
- 启动后台管理api服务:linjiashop-admin-api
- 修改linjiashop-admin-api中数据库连接配置
```properties
## 首次启动需要设置下列配置项设置为create,以便系统可以自动创建表并导入./import.sql测试数据文件,
## 如果下面配置无法自动建表并导入测试数据文件;则可以手动初始化数据库,手动使用的初始化文件文件位于:doc/database.sql
spring.jpa.hibernate.ddl-auto=create
```
- 启动linjiashop-admin-api主类:cn.enilu.flash.api.AdminApiApplication,访问http://localhost:8082/swagger-ui.html , 保证api服务启动成功
- 启动后台管理的前端界面:linjiashop-admin
- 运行 npm install --registry=https://registry.npm.taobao.org
- 运行npm run dev
- 启动成功后访问 http://localhost:9528 ,登录,用户名密码:admin/admin
- 启动手机端商城
- 启动手商城的api服务:linjiashop-mobile-api
- 修改linjiashop-mobile-api中数据库连接欸配置
- 启动linjiashop-mobile-api主类:cn.enilu.flash.MobileApiApplication,访问http://localhost:8081/swagger-ui.html , 保证api服务启动成功
- 启动手机商城的前端:linjiashop-mobile
- 运行 npm install --registry=https://registry.npm.taobao.org
- 运行npm run dev
- 启动成功后访问 http://localhost:8080/#/index
- 微信小程序开发
- 首先启动后台api服务,和h5公用一个后台服务,即:linjiashop-mobile-api
- 进入linjiashop-wxapp目录
- 运行 npm install --registry=https://registry.npm.taobao.org
- 运行npm run dev
- 启动微信开发工具导入linjiashop-wxapp/dist/wx 目录即可预览小程序
## 技术交流
- QQ群:254059156
- [商业支持](../other/xiaomiquan.html)
- 微信:myenilu,添加请备注:邻家小铺
# 资源
本节会整理提供一些助于开发的相关资源文档,在开发过程中学会恰当的里用这些资源将会使开发过程如虎添翼,事半功倍!。
## 前端
### 阿里巴巴矢量图库
- [https://iconfont.cn](https://iconfont.cn)
- 这个站点是阿里巴巴维护的一个图标站点,里面有极其丰富的图标,如果开发过程中需要一些图标而又不想麻烦设计师,那么可以来这里找找,应该不会让你失望。
### vue-element-admin
- [https://panjiachen.gitee.io/vue-element-admin-site/zh/](https://panjiachen.gitee.io/vue-element-admin-site/zh/)
- linjiashop-admin使用了vue-element-admin作为基础框架,基于linjiashop-admin开发之前强烈建议先看下vue-element-admin的官方文档
## Vue.js
- [https://vuejs.org](https://vuejs.org)
- vuejs官方文档,不说了,你懂得
## Vant
- [https://youzan.github.io/vant/#/zh-CN/intro](https://youzan.github.io/vant/#/zh-CN/intro)
- linjiashop-mobile项目使用了Vant组件,上面是其官方文档
## Vant-weapp
- [https://youzan.github.io/vant-weapp/#/intro](https://youzan.github.io/vant-weapp/#/intro)
- linjiashop-wxapp使用了Vant-weapp作为基础的ui组件,上面是其官方文档
## mpvue
- [http://mpvue.com/](http://mpvue.com/)
- linjiashop-wxapp使用了mpvue作为基础框架,上面为其官方文档
## 后端
## Spring Boot
- [https://qbgbook.gitbooks.io/spring-boot-reference-guide-zh/content/](https://qbgbook.gitbooks.io/spring-boot-reference-guide-zh/content/) 文档基于Spring Boot1.4.1的英文文档翻译
- [https://www.breakyizhan.com/springboot/3028.html](https://www.breakyizhan.com/springboot/3028.html) 文档基于Spring Boot2.0.1的英文文档翻译
- 本系统基于Spring Boot2.1.1开发,所以建议开发过程中多翻翻第二个在线文档,第一个文档可以作为参考。
## web-flash
- [http://enilu.github.io/web-flash](http://enilu.github.io/web-flash)
- 后台管理和接口基于web-flash改造,可以参考该项目[官方文档](http://enilu.gitee.io/web-flash)
# 接口设计规范
本项目采用前后端分离的架构方式,即前端采用vuejs开发界面,后端采用spring boot提供api服务。
本节说明开发过程中接口的基本设计规范,开发人员可以根据实际情况做调整,但是如果你打算为本项目提交代码,请尽量遵守下面规范
## 综述
- 前端部分包括手机h5(linjiashop-mobile),微信小程序(linjiashop-wxapp),app([linjiashop-flutter](https://gitee.com/microapp/linjiashop-flutter),[github](https://github.com/microapp-store/linjiashop-flutter))
- 已上前端项目公用一个api服务:linjiashop-mobile-api
# 后端
- 所有接口必须指定method,
- 例如下面代码必须指定method为DELETE而,不能不指定method
```java
@RequestMapping(value = "{id}",method = RequestMethod.DELETE)
public Object remove(@PathVariable("id") Long id){
Long idUser = getIdUser();
addressService.delete(idUser,id);
return Rets.success();
}
```
- 所有接口必须通过method明显显示其操作意思,比如获取数据:GET,删除数据:DELETE,编辑数据:POST(本项目不使用PUT)
- GET方法尽量使用@PathVariable注解来获取参数,除非参数过于复杂则采用@RequestParam来接收,相应的前端也使用对应的方式提交参数
- POST方法 ,如果参数过少可以采用@PathVariable或者@Requestaram来接收,如果参数较多则采用@RequestBody来接收参数
- DELETE方法尽量根据id去删除数据,接收参数方式尽量使用@PathVariable来接收
# 前端
- 针对上述后端接收参数的方式,前端要使用对应的方式提交参数
# 商品规格设计
参考自:https://www.jianshu.com/p/af7621dc71a9
本系统商品配置中允许单规格和多规格,其中单规格实际上就是无规格
## 数据库设计
为支持商品多规格需求,新增了attr_key和attr_vall两张表来维护商品品类的规格字典信息
新增了sku表来配置具体某个商品的上架sku信息
- attr_key表和商品类别是多对一的关系,即一类商品的规格是在商品类别上维护好的,不能在维护商品的时候随意更改。
- attr_val配置了每种属性的可选属性值列表,该值也在商品类别中维护,商品维护中只能选择,不能修改。
- sku表中通过code来存放具体规格值信息多个规格值id(id_attr_val)之间用半角逗号(,)分隔,
- 例:对于手机品类配置了两种属性名:版本和颜色,针对版本和颜色分别由两种属性值可选:
```
手机品类规格名:
id attr_name id_category
1 版本 1
2 颜色 1
```
```
手机品类规格值:
attr_val id_attr_key
3GB+32GB 1
4GB+64GB 1
珊瑚橙 2
深海蓝 2
```
```商品sku配置:
code code_name id_goods marketing_price price stock
1,3 3GB+32GB,珊瑚橙 1 69900 100
1,4 3GB+32GB,深海蓝 1 69900 100
2,3 4GB+64GB,珊瑚橙 1 79900 74900 100
2,4 4GB+64GB,深海蓝 1 79900 74900 100
```
## 后台管理商品规格维护
后台管理上架商品的时候,需要录入商品的上架规格信息
- 单(无)规格商品配置示例:
![无规格商品配置](../img/attr/single_attr.jpg)
- 多规格商品配置示例:
![多规格商品配置1](../img/attr/multiple_attr1.jpg)
![多规格商品配置2](../img/attr/multiple_attr2.jpg)
## 用户端如何使用sku配置
### 在商品详情页回返回商品基本信息和商品sku配置,
- 配置示例:
```json
{
"goods":{
"descript":"5000mAh超长续航",
"detail":"商品详情",
"gallery":"81,82,83,84",
"id":"1",
"idCategory":"1",
"name":"红米8A",
"pic":"36",
"price":69900,
"stock":400
},
"sku":{
"hide_stock":false,
"none_sku":false,//false表示商品有规格信息,true表示无规格信息
"price":69900,
"tree":[//商品规格名列表
{
"k_s":"s1",
"k":"版本",
"v":[
{
"id":"1",
"name":"3GB+32GB"
},
{
"id":"2",
"name":"4GB+64GB"
}
]
},
{
"k_s":"s2",
"k":"颜色",
"v":[
{
"id":"3",
"name":"珊瑚橙"
},
{
"id":"4",
"name":"深海蓝"
}
]
}
],
"list":[//商品sku列表
{
"price":69900,//价格
"id":"1",
"s1":"1",//表示id为1的规格名(版本)对应的的规格值的id是1(3GB+32GB)
"s2":"3",//表示id为2的规格名(颜色)对应的的规格值的id是3(珊瑚橙)
"stock_num":100 //库存
},
{
"price":69900,
"id":"2",
"s1":"1",
"s2":"4",
"stock_num":100
},
{
"price":74900,
"id":"3",
"s1":"2",
"s2":"3",
"stock_num":100
},
{
"price":74900,
"id":"4",
"s1":"2",
"s2":"4",
"stock_num":100
}
],
"stock_num":400
}
}
```
### 用户下单
用户下单的时候需要判断sku.none_sku的值,如果为true,则下单的时候传递商品id,下单数量即可,如果为false,
说明是多规格商品,要求用户必选选择相应的规格才可以下单,下单的时候还需要将id_sku传到后台
### 购物车和订单展示
- 展示购物车和顶顶那列表和详情的时候,展示的价格和商品名称分别取:price和title,而不应该取商品的价格goods.price和名称goods.name
# banner设计
本节主要介绍商城列表中中的banner的设计和用法
![banner](../img/banner.jpg)
本系统中的banner模块设计为一个通用的banner模块,即设计目标不仅在商城系统中可以用,在其他任意系统都可以用。
## 表设计
该模块设计的表主要为:t_cms_banner
该表主要有以下关键字段:
- page:代表要打开的页面
- 如果内容以http开头,则一般标识打开外部系统(界面)
- 如果内容不以http开头,则打开内部系统界面,例如,如果内容为goods,标识打开商品详情界面
- param:打开的页面要传递的参数
- 参数以json形式传递,以下面参数为例表示传参为id=1
```json
{"id": 1}
```
- idFile: 上传的图片文件对应的id
- title:banner描述信息
## 后台管理
- 后台管理的banner维护在cms模块中,目前仅提供添加和删除功能,如果需要修改,则可以通过先删除再添加的方式达到修改的目的
- ‘商品管理’-‘商品类别’中维护商品类别和banner的关系
## 前端使用
- 商城模块目前提供了t_shop_category_banner_rel表来维护不通商品分类对应的的banner信息
- 系统提供了获取商品分类及各个分类下的banner列表,数据样例参考:http://linjiashop-mobile-api.microapp.store/category/list
- 前端的具体用法参考 “表设计”小结的page和param介绍
# 开发指南
## 系统架构图
![系统架构图](../img/architecture.jpg)
## 项目模块
- linjiashop-admin PC端后台管理的前端网页
- linjiashop-admin-api PC端后台管理的api服务
- linjiashop-mobile 手机商城的前端网页
- linjiashop-mobile-api 移动端商城的api服务(h5,小程序,app都用改api服务作为后台接口)
- linjiasho-wxapp 微信小程序商城
- linjiashop-core 基础模块,包括工具类,dao,service,bean等内容
- linjiashop-generator 代码生成模块,根据实体生成dao,service,后台管理的controller和页面,配合IDEA 代码生成插件[webflash-generator](https://plugins.jetbrains.com/plugin/12648-webflash-generator)使用效果更好
## 基础模块
基础模块主要包含下面两个子模块:
- linjiashop-core 基础模块
- linjiashop-generator 代码生成模块,如果不使用代码生成功能,可以删除掉该模块
### linjiashop-core
- linjiashop-core是项目的核心模块,分别被两个api模块依赖:linjiashop-admin-api(后台管理服务)和linjiashop-mobile-api(用户端接口服务)
- 该模块拷贝自[web-flash](http://enilu.gitee.io/web-flash)的flash-core模块。在flash-core模块的基础上增加了业务相关的entity,repository,service
- 该模块是一个基于Spring Boot的标注jar模块,主要依赖了以下核心库:
- Spring Boot相关:web,jpa,jdbc
- alibaba druid作为数据源
- ehcache 作为本地缓存;这里之所以没有使用redis,主要是为了减小开发测试的复杂度.方便开发
- shiro和jwt作为基础的权限模块,linjiashop-core封装了权限基础内容,然后在两个api服务中分别配置自己的权限过滤规则
- quartz 来完成定时任务功能
- 一些util工具包:Guava,fastjson,Apache Commons系列工具包
- jxls 来做导出excel功能,可以根据配置好的excel模板生成excel表格
- Lombok用来生成实体的set,get方法,所以将本项目导入开发环境后,需要先保证开发工具安装了Lombok插件
- 该模块封装了常用的增删改查操作,基本上能满足日常90%的数据库操作需求,因此在自定义service方法或者repository方法的时候最好先看看封装的BaseService和BaseRepository是否已经有方法可以满足业务需要
## 后台管理
后台管理功能有两部分组成:linjiashop-admin(后台管理界面)和linjiashop-admin-api(后台管理api服务)
- linjiashop-admin 是一个基于[Vue.js](https://cn.vuejs.org/)&[Element](https://element.eleme.cn/#/zh-CN)的前端项目
- linjiashop-admin-api是一个基于Spring Boot的后端web服务
### linjiashop-admin
- linjiasho-admin的基础功能克隆自[web-flash](http://enilu.gitee.io/web-flash)的flash-vue-admin目录
- 后台管理的基础通用模块(非业务模块)请参考web-flash的在线文档,包括国际化,缓存的使用,定时任务管理,消息管理(短信,邮件模板配置,消息发送),导出excel,权限,日志,字典等等
- linjiashop-admin在flash-vue-admin的基础上新增了商城模块,商城模块主要包括如下功能
- 商品类别维护
- 商品维护
- 购物车列表
- 订单管理
- 前端用户管理
### linjiashop-admin-api
- 该模块为linjiashop-admin提供数据接口服务
- 开发过程中可以通过swagger来调试接口,通过swagger提供了在线测试工具,项目启动后,可以访问https://ip:端口/swagger-ui.html,比如本项目演示环境的api测试地址为:[http://linjiashop-admin-api.microapp.store/swagger-ui.html](http://linjiashop-admin-api.microapp.store/swagger-ui.html)
- 测试的时候,需要先调用/account/login登录系统并获取token,然后调用每个接口测试的时候将token放进去
- 如果要定义自己的过滤规则,可以通过修改:cn.enilu.flash.api.config.ShiroConfig中的配置来实现。
## 用户端系统
用户端系统包括两部分,
- linjiashop-mobile-api 数据接口服务
- 用户端,目前提供了三端:
- linjiasho-mobile(手机H5),
- linjiashop-wxapp(微信小程序),
- linjiashop-flutter(app),由于app项目特殊性,单独放在另外一个仓库[gitee](https://gitee.com/microapp/linjiashop-flutter),[github](https://github.com/microapp-store/linjiashop-flutter)
### linjishop-mobile-api
**用户端api由于是一个api提供三端(H5,小程序,app)使用,所以开发过程中要考虑兼容性**
- 比如banner设计,就不能简单的配置个url就行了,h5通过url可以打开一个界面,但是小程序不方便打开外部链接,就必须做具体的界面来展示banner信息。诸如此类接口要考虑全面。
- 目前系统还在开发中,为避免接口复杂化,所以接口并没有添加版本号。但是在真实产品中,需要考虑到app有不同的版本,接口也不能简单粗暴的调整,应该增加版本管理。
- 用户端接口和后台管理的接口有一些区别,区别在于:后台管理所有操作都必须登录才能操作,而用户端则有可以不登录就可以获取的数据接口,针对这块mobiel-api中做如下设计:
- /user开头的数据请求都必须登录才可以请求,
- 如果用户没有登录就获取/user开头的接口,会返回401,
- 用户端系统回自动判断如果收到401则跳转至登录界面
- 如果你对上述规则有自己的想法可以进行在cn.enilu.flash.config.ShiroConfig中进行调整,当然调整后要确保前端项目也做好适配
- mobile-api和admin-api公用了linjiashop-core模块,也即公用了entity,repository,service层的代码,因此在调整这些代码的时候要确保和后台管理不要有冲突,尤其是service层的代码
## linjiashop-mobile
- linjiashop-mobile 使用了有赞vant作为ui组件,开发过程请参考有赞vant的[官方文档](https://youzan.github.io/vant/#/zh-CN/intro)
- linjiashop-mobile 是一个标注你得使用vue.js构建的前端项目,有问题翻vue.js和vant的官方文档和issue
## linjiashop-wxapp
- linjiashop-wxapp 使用mpvne作为基础框架,使用vant-weapp作为ui框架,开发过程请参考这两个开源组件的官方文档和issue,这两个项目都是很成熟的开源项目,基本上开发过程遇到的问题翻一翻官方文档和issue都能解决。[mpvue](http://mpvue.com),[vant-weapp](https://youzan.github.io/vant-weapp/#/)
- 由于小程序的限制,所以并不是所有vue.js的特性都能用在小程序中,因此开发之前强烈建议把mpvue的官方文档先看一遍(本身也不多),主要是把mpvue开发小程序和vue.js开发的一些区别了解下。免得后期遇到莫名其妙的问题手足无措。[mpvue模板语法](http://mpvue.com/mpvue/#%E6%A8%A1%E6%9D%BF%E8%AF%AD%E6%B3%95)
## app商城
- app商城由于其特殊性并没有和本项目其他功能放在一个项目目录下,而是放在单独一个仓库,仓库地址:仓库地址[gitee](https://gitee.com/microapp/linjiashop-flutter),[github](https://github.com/microapp-store/linjiashop-flutter)
- app 商城采用flutter1.9开发,安装flutter的时候切记要安装指定的版本。开发之前请认真阅读linjiashop-flutter的readme文档
## 开发约定
- 本项目主要技术栈为Spring Boot2,Spring Data Jpa,Vue.js,Flutter。所以开发过程中请首选遵循已上技术官方的一些约定
- 本项目开发过程使用了Lombok插件来生成bean的set,get方法。所以请务必为开发工具安装lombok插件,以避免项目中实体由于没有set,get方法无法编译的问题。
- 本项目封装了service和repository的常用操作方法到基类;新建service和repository应继承这两个父类:BaseService,和BaseRepository
- 本项目封装了BaseEntity和ShopBaseEntity 两个实体类的基类。其他实体类都应该继承这两个实体中的一个,具体继承哪个请参考下面建议
- BaseEntity比ShopBaseEntity多了createBy和modifyBy两个字段。
- BaseEntity主要用在系统基础功能相关实体,比如系统参数Cfg,定时任务实体Task等;这类实体的数据维护主要在后台管理系统中维护,因此配合注解:@EntityListeners(AuditingEntityListener.class) 可以在维护的时候自动设置其维护人信息
- ShopBaseEntity主要跟前端用户操作相关的实体相关,比如订单,购物车等信息,这类信息一般不需要自动设置维护人信息,而是通过idUser跟前端用户关联.
- 本项目开发运行设计相关软件版本如下:
- Tomcat8及其已上
- MySQL5.6及其已上
- Jdk1.8及其已上
# vant weapp和mpvue入坑指南
**如果你能静下心来把vant-weapp和mpvue的官方文档读一遍,那么你是不需要看本文档的**
**如果你遇到问题先去vant-weapp和mpvue的官方issue里翻一番,那么你是不需要看本文档的**
**如果你看到这里;恭喜你,你距离伟大的程序猿又远了一步**
本节主要介绍再试用vant weapp和mpvue开发过程中遇到的各种坑。当然这个也不能怪谁,毕竟微信综合各方面考虑(性能,安全等)裁剪掉了原生H5的很多原生功能。
而mpvue本质上是把原生代码(vue)转换成小程序代码。实际项目中,总有一些情况mpvue是考虑不到的。但是没问题,俗话说条条大道通罗马,方法A不行,总能找到方法B;俗话说,你遇到的问题,总有人比你先遇到,多按照本章开头的方法去找找解决方案,总能找到你想要的答案。
关于vant weapp和mpvue配合使用的坑,请先阅读下官方的说明:
[mpvue官方避坑指南](http://mpvue.com/mpvue/#%E6%A1%86%E6%9E%B6%E5%8E%9F%E7%90%86)
[vant weapp和mpvue入坑大全](https://github.com/youzan/vant-weapp/issues?utf8=%E2%9C%93&q=mpvue)
## 本项目中的避坑经历(待完善)
### 商品详情页添加到购物车的时候,选择商品规格时,无法通过更新sku.tree数组中的数据来更新规格视图未选中状态
在这里使用数组的方法,如slice,push,等都没有用,必须使用如下方法可以
```
this.sku.tree = [...this.sku.tree]
```
# 对接微信
本章节从获取微信token,获取微信信息等几方面来说明系统如何和微信做对接。
## 基础配置
目前系统针对微信对接在参数管理中提供了如下的参数配置,后期如果有需要可以自行添加
```
- 微信商户id: weixin.app.id
- 微信密钥: weixin.app.secret
- 微信获取token的地址: weixin.access.token.url
- 微信获取ticket的地址: weixin.js.api.ticket.url
- 微信token: weixin.access.token
- 微信ticket: weixin.js.api.ticket
```
- 上面参数中前四个需要事先配置好,具体参数代表的意思不再赘述,不明白的请自行查阅微信官方文档或者google。其中前四项需要根据自己的实际情况配置,后两项参数的值由定时任务定时调用微信接口去获取。
- 本系统提供了一个定时任务:UpdateWeixinTokenJob 来定时获取微信token和ticket,获取成功后会存放到参数表中。
- 另外建议微信相关配置参数的key值都以"weixin"开头,这样可以复用后台管理中参数管理的分组功能;如下图所示,微信相关配置都在公众号配置组下:
![参数分组功能](../img/develop/cfg_weixin.jpg)
### 定时任务获取微信token和ticket
- 微信token和ticket是针对微信相关操作的基础。大部分微信相关操作都需要用到这两个值。
- 系统默认提供了定时任务:UpdateWeixinTokenJob 来每隔一个小时获取一次上面两个值并存在参数配置表(t_sys_cfg)中
## 获取用户信息
linjiashop-mobile项目提供了用户登录后获取微信用户基本信息(微信昵称、头像、openid)的功能
src/view/user/user.js中当用户成功获取基本信息后,会紧接着获取微信相关信息。
部分代码示例:
```javascript
init() {
userApi.getUserInfo().then(response => {
const url = window.location.href
if(url.indexOf('localhost')>-1 || url.indexOf('127.0.0.1')>-1) {
console.log('开发环境不获取openid')
}else{
const userAgent = window.navigator.userAgent.toLowerCase()
//使用微信访问本系统的时候获取微信用户基本信息,否则不获取
if(userAgent.indexOf('micromessenger'>-1)) {
this.processOpenid();
}
}
}).catch((err) => {
this.$router.replace({path:'login',query:{redirect:'user'}})
})
}
```
- 后台具体获取逻辑可以从上述代码进行调试跟进,继而查看和调整。
## 微信支付
linjiashop-mobile集成了微信支付来支付订单金额。支持微信支付通过以下步骤实现。
### 参数配置
- 配置微信支付相关参数:在配置文件linjiashop-mobile-api/src/main/resource/application-dev(prod).properties:
```properties
wx.app-id=服务商的APPID
wx.app-secret=APPID对应的接口密码
wx.mch-id=商户号
wx.mch-key=API密钥
# 支付结果通知地址
wx.notify-url=http://linjiashop.microapp.store/prodp-api/pay/wx/notify
#商户证书文件路径
wx.key-path= /data/linjiashop...
```
### maven依赖
- 本系统使用了weixin-java-pay封装的微信的java sdk,因此需要在maven以来中加入改项目,另外小程序和h5用的同一个后台,因此同时也加入了小程序的java sdk:weixin-java-miniapp(小程序暂未对接)
```xml
<dependency>
<groupId>com.github.binarywang</groupId>
<artifactId>weixin-java-pay</artifactId>
<version>3.3.0</version>
</dependency>
<d3.ependency>
<groupId>com.github.binarywang</groupId>
<artifactId>weixin-java-miniapp</artifactId>
<version>3.</version>
</dependency>
```
- 后台的微信支付相关对接代码参阅:WeixinPayService
### 前端提交微信支付
前端支付相关代码:
- 提交支付:linjiashop-mobile/src/view/order/payment/index.vue
- 支付结果界面:linjiashop-mobile/src/view/order/payment/callback/index.vue
### 支付结果通知
- 前端发起微信支付提交之后,微信会通过配置的通知地址将支付结果主动送过来,本项目默认的的微信通知地址应配置为:http://域名/prod-api/pay/wx/notify;可根据实际情况自行调整
```java
/**
* 微信支付回调
* @return
*/
@RequestMapping(value = "wx/notify",method = RequestMethod.POST)
public Object wxNotify(){
String msg = weixinPayService.resultNotify();
return Rets.success(msg);
}
```
## 微信模板消息(未开发)
# Change log
## v0.6
[gitee](https://gitee.com/microapp/linjiashop/releases/v0.6) [github](https://github.com/microapp-store/linjiashop/releases/tag/v0.6)
### Issues
- echarts随着窗口缩放自适应
- 用户个人中心增加收藏商品管理功能
- 对接快递鸟物流查询服务
- 编辑sku使用逻辑删除代替物理删除
- 购物车管理功能,可以删除购物车中的商品
- banner编辑时针对参数进行必须为json字符串的验证
- 后台管理中显示用户微信头像
### Fixes
- 分页查询bug
- 升级webpack导致的组件无法加载的问题
- 定日日志任务异常日志没有正常显示
- 更新缓存的时候连带更新常量工具类中使用的本地(TimeCacheMap)缓存
- 编辑商品规格信息的时候允许规格重复的问题
- 商品类别中维护商品规格属性名的时候可以重复的问题
## v0.5
[gitee](https://gitee.com/microapp/linjiashop/releases/v0.5) [github](https://github.com/microapp-store/linjiashop/releases/tag/v0.5)
### Issues
- 对接微信-获取微信用户信息
- 重构日志记录方式(直接使用实体类的comment注释代替自定义AbstractDictMap子类的方式来描述更改的字段信息)
- H5端完成微信支付的对接
- 用户下单的时候判断库存避免超卖
- mobile端针对后台的500错误使用toast提示统一显示处理
### Fixes
- 【后台管理】商品编辑界面上传的图片无法显示
- 【后台管理】新建立的角色配置给用户后无法登录
- 后台管理(admin-api)和用户端(mobile-api)参数由于缓存无法同步的问题
- 【后台管理】业务日志和登录日志创建日期不显示的问题
- 【后台管理】不配置菜单权限时登录管理员无法获取并生成左侧菜单树
- BaseEntity使用hibernate的@CreationTimestamp和@UpdateTimestamp代替spring的@CreatedDate和@LastModifiedDate
- 【后台管理】商品更新的时候从多规格更改位单规格的时候逻辑错误
- 对下单的时候库存做事务管理和加锁处理,以避免超卖问题
- 定时任务执行异常日志没有正常显示
- 静态界面段配置问题导致无法跨域
## v0.4
[gitee](https://gitee.com/microapp/linjiashop/releases/v0.4) [github](https://github.com/microapp-store/linjiashop/releases/tag/v0.4)
### Issues
- 【后台管理】管理员给订单添加备注信息
- 【后台管理】维护物流公司
- 【后台管理】增加订单发货功能
- 【后台管理】增加导出订单excel报表功能
- 针对订单全流程生命周期添加操作日志
- 基础框架封装支持关联查询;封装根据原生sql语句查询返回List Map代替List Object[]
- 【后台管理】商品类别中维护该类商品规格名信息
- 【后台管理】订单管理增加高级检索功能
- 【后台管理】参数管理增加分组功能,方便分组维护参数
- 增加定时任务获取微信token
### Fixes
- 【H5】用户提交订单的时候收货地址缓存问题
- 【H5】用户跳转到其他页面再跳转回来会话信息丢失的问题
- 【后台管理】banner上传后界面无法回显的问题
- 【H5】跳转到其网站再跳转回来会话信息丢失的问题[将会话信息存储在localStorage]
- 【H5】提交订单时收货地址缓存了上一个登录用户的收货地址的问题
- 【H5】使用手机号验证码登陆后后没有正常返回登录用户信息
- 【H5] 用户登录的时候没有记录上用户最后登录时间
## v0.3
[gitee](https://gitee.com/microapp/linjiashop/releases/v0.3)
### Issues
- 【后台管理】压缩svg图标
- 【H5】新增未登录状态和购物车为空状态下的购物车界面
- 【H5】商品下架后商品详情页显示该商品已下架
- 【H5】新增未登录状态和购物车为空状态下的购物车界面
- 【后台管理】后台新增定时任务定时更新微信token
- 【H5】在商品详情页商品添加到购物车后购物车图标显示商品数量
- 【H5】新增商品收藏功能
- 优化图片资源请求地址:图片资源标识使用uuid代替自增的id
- 完善后台管理的专题管理功能
### Fixes
- 【后台管理】修复并完善权限配置功能
- 【后台管理】商品编辑菜单数据初始化错误
- 【后台管理】修改管理员密码后缓存处理错误导致重新登录失败
- 【后台管理】 banner上传问题
## v0.2
[gitee](https://gitee.com/microapp/linjiashop/releases/v0.2) [github](https://github.com/microapp-store/linjiashop/releases/tag/v0.2)
### Issues
- 【API】 Token过期自动刷新
- 【后台管理】 用户列表增加用户头像,注册时间列,添加过滤功能,增加用户详情页内容
- 【H5】 添加用户使用手机号自主注册账号功能
- 【后台管理】 优化dashboard页,从后台获取展示数据
- 【H5】 新增设置中心,添加用户自维护功能,包括上传头像,修改昵称,性别,密码,更换手机等
- 【后台管理】 新增专题管理功能,对专题信息进行维护
- 【H5】 专题推荐
- 【后台管理】 热门商品和新品推荐商品的维护
- 【H5】 新增个性化首页,首页内容包括:专题推荐,热门商品推荐,新品推荐
### Fixes
- 【H5,后台管理】用户户没有权限操作的时候浏览器自动弹出验证框的问题
## v0.1
[gitee](https://gitee.com/microapp/linjiashop/releases/v0.1)[github](https://github.com/microapp-store/linjiashop/releases/tag/v0.1)
### Issues
- 【后台管理】 基础的管理功能:用户,权限,菜单,角色,定时任务,消息发送,日志,监控
- 【后台管理】 业务功能:商品类别维护,商品维护,banner维护,订单管理,购物车列表,用户列表
- 【H5,小程序】用户登录,商品列表,banner列表,搜索,商品详情,购物车,下单,历史订单
- 【APP商城】 另外发布了商城的app版本(基于Flutter):linjiashop-flutter
# 常见问题
## 本地开发正常,打包运行的时候提交中文内容乱码,检查了数据库编码也没问题?
打包为jar包运行的时候可以指定运行时编码为UTF8:
```
java -Dfile.encoding=utf-8 -jar xxxxxxx.jar
```
## 打包vue项目总是下载依赖包失败
- 删除node_modules目录
- 使用淘宝源重新下载安装依赖,剩下的交给人品
```shell
npm install --registry=https://registry.npm.taobao.org
```
## 使用代码生成器的时候生成不了代码
下载项目好,首先运行mvn package -DskipTestss将项目打包成功,然后再生成,代码生成器读取实体类的class文件进行生成,所以必须构建生成class文件
## Invalid character found in the request target. The valid characters are defined in RFC 3986
将api部署在tomcat中的时候,如果前端请求参数有特殊字符,例如{},[]等,tomcat会报上述错误,
出现这个错误的原因是不支持参数中的特殊字符,可以通过该如下方式借据:
- 在conf/catalina.properties中最后添加2行:
```properties
tomcat.util.http.parser.HttpParser.requestTargetAllow=|{}
org.apache.tomcat.util.buf.UDecoder.ALLOW_ENCODED_SLASH=true
```
- requestTargetAllow 只能配置|、{、} 允许这三个字符,对于其他的(例如" < > [ \ ] ^ ` { | } .),在请求时,仍然拦截,如果使用了|{}之外的其他字符那怎么办呢?那就还需要如下配置。
- 在conf/server.xml中的Connector节点中,添加2个属性:
```xml
relaxedPathChars="|{}[],"
relaxedQueryChars="|{}[],"
```
这2个属性,可以接收任意特殊字符的组合,根据需要可以自行增减。
**参考文档:** https://blog.csdn.net/ljheee/article/details/82051755
# 开发视频
**入门视频**
- [https://space.bilibili.com/525325274/channel/detail?cid=115895](https://space.bilibili.com/525325274/channel/detail?cid=115895)
- 上述入门视频基本可以带你快速熟悉本项目并进行开发。相信我,如果你能将本文档认真看看,那么你连视频教程都不用看的。文档最重要!!!
- 当然本系统录制有更全面的视频教程,如果你感兴趣可以通过下面方式获取。
- 方式一:邀请好友给以下两个项目star 8个(是合计8个,不是每个8个)即可。[linjiashop](https://gitee.com/microapp/linjiashop),[web-flash](https://gitee.com/enilu/web-flash)
- 方式二: 使用[捐赠页面二维码](donate.html)支付200元,即可购买全套视频。购买完成后加作者微信myenilu出示支付截图以获取视频
- 方式三:加入[知识星球](xiaomiquan.html),即可获赠全套视频,并且可以向作者一对一提问项目技术问题并获得及时的回答。
- 视频教程目录:
![视频ppt目录](../img/other/linjiashop_video.png)
# 知识星球
**这里可以做什么**
- 在这里你得任何问题都将予以回复。
- 在这里可以保证只要你不是榆木脑袋,肯定可以熟悉,了解,开发这个项目,基于这个项目开发其他项目、产品。
**为什么要建立一个问答社区(知识星球)**
- 随着qq群里人数增多,无效的问题越来越多,实在回答不过来,尤其是那种没头没尾的一句话问题,没有日志,没有截图。让人无法忍受。而且不少人喜欢私信问问题,
正常情况下,如果是一个好问题,在群里问我都会回答。但是总有人私信问一些无效问题,让人头大,既然这样,不如你来知识星球问,你付过钱了,你是大爷,想怎么问都行。
- qq群里问过的问题很多,重复的问题也很多,但是qq记录搜索做的不太好,导致好问题无法沉淀下来,重复回答,浪费时间。
## 加入方式:
- 方法1:邀请好友给以下两个项目(gitee上)star 10个(注意是合计10个即可,不是每个10个)即可,然后截图发给作者(微信:myenilu),作者核实过后会邀请你进来。[linjiashop](https://gitee.com/microapp/linjiashop),[web-flash](https://gitee.com/enilu/web-flash),然后截图发给作者(微信:myenilu),作者核实过后会邀请你进来。
- 方法2:扫描下图知识星球二维码直接支付即可加入
![小密圈](../img/other/xiaomiquan.png)
**声明**
QQ群依然会维护,只是随着人越来越多,有些问题可能回复不及时而已,或者一些无效问题,我会直接忽略。
# 克隆本项目
本项目地址为:[https://gitee.com/microapp/linjiashop](https://gitee.com/microapp/linjiashop),如果对你有用,欢迎给个star
另附github地址:https://github.com/microapp-store/linjiashop
项目共三个分支分别为:
- master 项目主分支:稳定版
- dev 开发分支:一些新功能后者实验性功能会先在该分支开发,不稳定
- gh-pages 项目在线文档
进入控制台输入以下命令将项目克隆到本地:
git clone https://gitee.com/microapp/linjiashop.git
# 配置项目
你已经下载项目,并且初始化好了数据库,那么接下来只需要更改相应的配置就可以运行该项目了
- 更改admin-api和mobile-api下的数据库配置:src/resources/application-dev.properties配置:
```properties
## 开发环境配置,根据实际情况调整数据库连接信息
spring.datasource.url=jdbc:mysql://localhost:3306/linjiashop?useUnicode=true&characterEncoding=UTF8
spring.datasource.username=linjiashop
spring.datasource.password=linjiashop191028
```
# 初始化数据
本系统使用mysql数据库
- 在mysql中创建数据库 linjiashop和对应的账户密码
```sql
CREATE DATABASE IF NOT EXISTS linjiashop DEFAULT CHARSET utf8 COLLATE utf8_general_ci;
CREATE USER 'linjiashop'@'%' IDENTIFIED BY 'linjiashop191028';
GRANT ALL privileges ON linjiashop.* TO 'linjiashop'@'%';
flush privileges;
```
- 启动项目的时候会自动创建数据库并初始化系统数据,所以无需自己初始化数据
- 本系统通过Spring Boot的配置:spring.jpa.hibernate.ddl-auto=create 来初始化数据库,建议在生产环境中去掉该配置以避免将已经初始化好的数据库表和数据删除。
- 初始化语句为:linjiashop-admin-api/src/main/resources/import.sql,当配置spring.jpa.hibernate.ddl-auto=create的时候,系统启动会自动执行该语句初始化测试数据。
- 如果你是个传统的人;就是想要数据库文件,用传统的方式初始化数据库。doc/database.sql为你准备好了
# 20分钟把项目跑起来
## 真的20分钟吗?
NO, 明显不,都是骗人的啦.
## 那为啥还要这样写?
总不能写10分钟跑完吧? 虽然网上很多很多10分钟快速入门,但作为一个不随便的人,我可没办法评估你的鼠标键盘操作速度和头脑CPU的运算频率,所以还是写20分钟比较保险的.
## 本章知识点
- [克隆项目](./clone.md)
- [初始化数据](./initDb.md)
- [配置项目](./config.md)
- [启动项目](./startup.md)
\ No newline at end of file
# 启动项目
## 启动后台管理api服务:linjiashop-admin-api
- 右键直接运行cn.enilu.flash.api.AdminApiApplication 类即可已启动后台管理api
- 启动成功后访问http://localhost:8082/swagger-ui.html
## 准备测试图片
- 下载项目测试数据的图片:链接:链接:[https://pan.baidu.com/s/1Ppfgy2wR1nW0l-QMYHFGKw](https://pan.baidu.com/s/1Ppfgy2wR1nW0l-QMYHFGKw) 提取码:wo8q ,将图片存放到t_sys_cfg表中system.file.upload.path配置的目录下;**注意**:该目录路径为绝对路径
## 启动后台管理前端界面:linjiashop-admin
- 进入linjiashop-admin目录
- 命令行窗口运行 npm install --registry=https://registry.npm.taobao.org
- 运行 npm run dev
- 启动成功后访问 http://localhost:9528,登录,用户名密码:admin/admin
![vue](../img/admin.gif)
## 启动移动端api服务:linjiashop-mobile-api
- 右键直接运行cn.enilu.flash.MobileApiApplication 类即可已启动移动端api服务
- 启动成功后访问http://localhost:8081/swagger-ui.html
## 启动移动端h5界面:linjiashop-mobile
- 进入linjiashop-mobile目录
- 命令行窗口运行 npm install --registry=https://registry.npm.taobao.org
- 运行 npm run dev
- 启动成功后访问 http://localhost:8080
![vue](../img/mobile.gif)
## 本地调试微信小程序:linjiashop-wxapp
- 进入linjiashop-wxapp目录
- 命令行窗口运行 npm install --registry=https://registry.npm.taobao.org
- 运行 npm run dev
- 在微信开发工具中导入目录:linjiashop-wxapp/dist/wx目录即可
so,是不是很简单!
# 01-环境准备
首先计划在公众号上线,所以需要下面准备工作
- 要有个(企业认证的)公众号
- 要有服务器
- 要有域名
- 要开通微信支付
- 要有短信发送服务
## 要有个(企业认证的)公众号
- 自己本来有个公众号,使用朋友注册的公司注册的,所以,就有了企业注册的公众号
- 但是这个公众号没有做企业认证,所以需要朋友配合做公众号的企业认证
- 朋友帮忙做企业认证(此处省略难熬的2周时间:找营业执照,找公章,企业财务ukey密码忘掉,重置密码,没错朋友注册个公司也是瞎折腾玩)
## 要有个服务器
- 之前买了个2G内存的阿里云服务器,打算就用这个了,
- 虽然这上面已经部署了7个java程序,内存常年处于用满状态;
- 硬盘可用空间常态在5G以内。需要不定时清理空间
- 没办法,穷是原罪。
_服务器已经做过备案,没做过备案的同学可以自己根据阿里云的提示做即可,这个不麻烦_
## 要有域名
- 之前申请了microapp.store域名,打算使用两个二级域名分别做后台管理和手机h5
- 后台管理:wt1hd-admin.microapp.store
- 手机h5:wt1hd.microapp.store
## 要开通微信支付
- 微信支付是朋友帮忙开通的,因为需要企业资质相关信息。截至文章发出时间已经又一周时间了,还没有申请下来😳
- 微信支付开通过程选择少一点平台,因为有公众号,小程序,app,pc网站等平台可以复选,为了快速开通,最好先选择一个(公众号),避免开通过多平台需要的审核资料多,多了就容易出错通不过。
## 要有短信发送服务
- 注册,登录,以及后续的通知都需要给用户发送短信。
- 系统已经内置了腾讯云短信接口服务
- 去腾讯云申请短信接口服务。
- 申请短信的时候需要申请短信签名和短信模板,短信签名的申请需要企业资质信息(比如营业执照之类)。
- 短信模板申请下来后,配置到短信发送器中的“运营商模板编号“字段中。
_截至发文签名审核失败,还得继续折腾,哎_
**如果大家对上线运营笔记相关内容有意见和建议,请在gitee上issue评论区进行讨论:[邻家小铺上线日记评论区](https://gitee.com/microapp/linjiashop/issues/I1H4V3)**
# 02-环境准备
- 短信服务
- 服务器环境准备
- 前后端部署
- nginx配置
## 短信服务
果然短信签名有问题,因为我的腾讯云账号是我个人认证的,但是我要使用的这个短信签名的公众号是是企业认证的,
主体不一致,需要公众号主体授权给我个人。
太麻烦了,有没有简单的方法呢,细细看了下,还真有。腾讯云账号有种登录方式叫做使用微信公众号登录。那么我可以使用公众号账号来关联登录
登录进去后就已经自动用公众号主体(是个企业)做了实名认证
接下来申请签名就块多了,基本上十分钟内就可以批准
## 服务器环境准备
- 因为之前的服务器上已经安装了相关软件,所以个这个过程不赘述,自己谷歌百度完成安装即可。下面列出相关软件和版本:
- nginx:1.12.2
- mysql:5.6.47
- jdk:1.8.0_201
- tomcat:9
## 前后端部署
- admin-api和mobile-api分别打war包为:wt1hd-admin.war,wt1hd-mobile.war 将war包放在/opt/tomcat/webapps/目录下
- 前端项目部署:
- admin存放在:/opt/wt1hd/admin/
- mobile放在:/opt/wt1hd/mobile/
## nginx 配置
- 前端项目和前端api配置wt1hd-mobile.config,配置内容如下:
```
server {
listen 80;
server_name wt1hd.microapp.store;
access_log /data/app/runtime/log/nginx/wt1hd/mobile.access.log main;
location /{
alias /opt/wt1hd/mobile/;
index index.html index.htm;
}
//api服务配置
location /prod-api/{
proxy_ignore_client_abort on;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_read_timeout 600s;
proxy_pass http://localhost:8080/wt1hd-mobile-api/;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /usr/share/nginx/html;
}
}
```
- 后端项目和后端api配置:wt1hd-admin.config,配置内容如下:
```
server {
listen 80;
server_name wt1hd-admin.microapp.store;
access_log /data/app/runtime/log/nginx/wt1hd/admin.access.log main;
location /{
alias /opt/wt1hd/admin/;
index index.html index.htm;
}
location /prod-api/{
proxy_ignore_client_abort on;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_read_timeout 600s;
proxy_pass http://localhost:8080/wt1hd-admin-api/;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /usr/share/nginx/html;
}
}
```
- 注意我使用上面的配置的时候,前端的两个项目admin和mobile没有更改任何配置,分别运行npm run build:prod 和npm run build打包后直接用了。很多朋友打包部署这里遇到各种各样的问题,根本原因有两点,一是没有搞懂vue.config.js中的配置,二是对nginx的配置不明白不会用。
**如果大家对上线运营笔记相关内容有意见和建议,请在gitee上issue评论区进行讨论:[邻家小铺上线日记评论区](https://gitee.com/microapp/linjiashop/issues/I1H4V3)**
# 03-项目配置
- 数据库配置
- 图片目录配置
- 短信配置
## 数据库配置
- 创建数据库
```sql
CREATE DATABASE IF NOT EXISTS wt1hd DEFAULT CHARSET utf8 COLLATE utf8_general_ci;
CREATE USER '数据库账号'@'%' IDENTIFIED BY '数据库密码';
GRANT ALL privileges ON wt1hd.* TO 'wt1hd '@'localhost'; -- 限制只能本机访问
flush privileges;
```
- 在本地启动应用的时候自动生成表和插入初始化语句,然后将其通过mysqldump导出后,导入到服务器上的数据库
## 配置图片目录
- 打开后台管理的”系统管理“-》”参数管理“页面,在”系统配置“标签页种更改”系统默认上传文件路径“的参数为:/data/app/wt1hd/runtime/upload
## 短信配置
- 首先确保在腾讯云上申请好短信签名,我申请的短信签名是"外滩一号店”,短信签名也就是后续发送短信的时候最前面的内容,比如:【外滩一号店】校验码2838,请及时输入。。。
- 其次保证创建好短信模板,确认有一个模板编号
- 在腾讯云短信种的应用列表创建一个应用,系统默认回有一个。
- 在“系统管理”->“参数管理”的“消息配置”标签页种正确配置上以下三个参数:
- 腾讯sms接口appid
- 腾讯sms接口appkey
- 腾讯sms接口签名参数
- 在“消息管理”->"消息发送器中新建一个消息发送器,属性值如下:
- 名称:腾讯短信-注册登录短信验证码
- 发送类:tencentSmsSender
- 运营商模板编号:就是该小节第二部申请的那个短信模板的模板编号
- 在”消息管理“->”消息模板“中修改编码为”REGISTER_CODE“的记录的发送器为:上一步新添加的那个消息发送器:腾讯短信-注册登录短信验证码
**如果大家对上线运营笔记相关内容有意见和建议,请在gitee上issue评论区进行讨论:[邻家小铺上线日记评论区](https://gitee.com/microapp/linjiashop/issues/I1H4V3)**
# 04-安全配置
- mysql配置
- 后台管理配置
- 短信验证码发送次数限制
- 禁用swagger在线文档
本章节主要处于安全性考虑做了一些配置和修改
## mysql配置
- mysql修改为只允许本机登录
- 后期考虑将默认端口更改掉,目前默认是3306
## 后台管理配置
- 后台管理的账号从admin更改为更复杂的密码
## 短信验证码发送次数限制
为了避免短信的无端消耗,做了下面两个工作:
- 腾讯云做短信验证码发送次数限制
- 代码中同一个号码每天短信验证码发送次数限制
# 05-功能完善
本节主要不完全记录一些上线过程中更新的功能
## 优化获取用户微信信息的逻辑
针对获取用户微信信息做了下面几方面的优化:
- 一个手机号只能绑定在同一个微信号下
- 缓存用户的微信信息,避免每次到用户页面都获取微信登录信息
- 去掉获取微信信息的提示框
- 如果成功获取微信信息,使用微信昵称和头像代替之前的默认姓名和头像
- 用户管理中如果用户有微信头像,显示用户的微信头像
# 06- 对接微信支付
- 前面说过,上线一开始的时候就让朋友帮忙申请开通微信支付功能。
- 而系统本身已经具备微信支付功能,只需要将微信支付相关参数配置即可:
```properties
# 以下两个参数需要登录微信公众号后台获得
wx.app-id=微信公众号id
wx.app-secret=公众号密钥
# 以下相关参数需要登录微信支付商户后台获得
wx.mch-id=微信支付商户号
wx.mch-key=微信支付密钥
wx.notify-url=微信支付结果通知地址
# 商户证书文件路径
wx.key-path= 使用微信支付提供的证书生成程序生成证书文件,机器将文件:apiclient_cert.p12 放在系统指定路径上,这里配置绝对路径
```
测试支付成功
手机端截图:
![wechat-pay](../img/online/wechat_pay.jpg)
微信支付商户后台资金流水截图:
![wechat-pay-admin](../img/online/wechat_pay_admin.png)
# 邻家小铺上线日记
邻家小铺是业余时间开发的一个开源的单商户的B2C商城系统。发现了解这个项目的什么样的人都有。
- 有学生拿来做毕业设计的,
- 有刚入行的拿来作为SpringBoot 和Vue.js的入门学习项目的。
- 也有动手能力比较强的已经拿来做项目并且已经交付给客户了的。
这个过程中林林总总遇到过很多问题。其中有些问题很基础,而有些问题由于我自身局限(实在是实际工作经验中没有真正接触过商城产品或项目)有很多考虑不到的地方。。
因此想着将邻家小铺真正上线运营。通过这个过程来达到以下几个目的:
- 1,完善项目,使其不至于有些基本的错误。
- 2,记录整个上线运营过程,帮大家踩坑。
- 3,自己没有运营过一款产品,也是锻炼锻炼自己,本人爱好比较杂,惭愧的是都不是很精通 😳
整个上线计划是这样的:
- 将h5在公众号上线
- (平稳运行一段时间后)上线小程序和app
上线公众号名字暂定:**外滩一号店** ,或者扫描下面二维码关注
- 名字随便起的,欢迎吐槽,恕不理睬。
- 另外这个公众号是之前自己做各种项目实验的地方,所以有有些无关的历史文章。不要有疑问,恕不解释😄
![外滩一号店](../img/online/wt1hd.jpg)
下面会列出上线运营的笔记。后续不定期更新,也需一天一篇,也许几天一篇。总之基于实际上线运营过程进行记录。
**如果大家对上线运营笔记相关内容有意见和建议,请在gitee上issue评论区进行讨论:[邻家小铺上线日记评论区](https://gitee.com/microapp/linjiashop/issues/I1H4V3)**
整个上线笔记按照操作时间顺序无情感描述,有些混乱的地方稍微梳理。目的是真实记录和还原整个上线流程😄
- [01-环境准备](./day01.md)
- [02-环境准备](./day02.md)
- [03-项目配置](./day03.md)
- [04-安全配置](./day04.md)
- [05-优化获取用户微信信息的逻辑](./day05.md)
- [06-对接微信支付](./day06.md)
{
"scripts": {
"docs:dev": "vuepress dev docs",
"docs:build": "vuepress build docs"
},
"devDependencies": {
"@vuepress/plugin-google-analytics": "^1.0.0-alpha.0"
}
}
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<parent>
<groupId>cn.enilu</groupId>
<artifactId>linjiashop</artifactId>
<version>1.0.0-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<packaging>jar</packaging>
<artifactId>linjiashop-admin-api</artifactId>
<version>1.0.0-SNAPSHOT</version>
<dependencies>
<dependency>
<groupId>cn.enilu</groupId>
<artifactId>linjiashop-core</artifactId>
<version>1.0.0-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger2</artifactId>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-core</artifactId>
<version>5.2.8.RELEASE</version>
</dependency>
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger-ui</artifactId>
</dependency>
<!-- spring-boot-devtools -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
<version>2.2.6.RELEASE</version>
<optional>true</optional>
<scope>true</scope>
</dependency>
</dependencies>
<build>
<finalName>admin-api</finalName>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<fork>true</fork> <!-- 如果没有该配置,devtools不会生效 -->
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.0</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
<encoding>UTF-8</encoding>
</configuration>
</plugin>
</plugins>
</build>
</project>
package cn.enilu.flash.api;
import cn.enilu.flash.dao.BaseRepositoryFactoryBean;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.autoconfigure.domain.EntityScan;
import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.boot.web.servlet.support.SpringBootServletInitializer;
import org.springframework.cache.annotation.EnableCaching;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.data.jpa.repository.config.EnableJpaAuditing;
import org.springframework.data.jpa.repository.config.EnableJpaRepositories;
/**
* ApiApplication
*
* @author enilu
* @version 2018/9/11 0011
*/
@EnableCaching
@SpringBootApplication
@ComponentScan(basePackages = "cn.enilu.flash")
@EntityScan(basePackages="cn.enilu.flash.bean.entity")
@EnableJpaRepositories(basePackages = "cn.enilu.flash.dao", repositoryFactoryBeanClass = BaseRepositoryFactoryBean.class)
@EnableJpaAuditing
public class AdminApiApplication extends SpringBootServletInitializer {
@Override
protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
return application.sources(AdminApiApplication.class);
}
public static void main(String[] args) {
SpringApplication.run(AdminApiApplication.class);
}
}
package cn.enilu.flash.api.config;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.CorsRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;
/**
* 跨域配置
*
* @author enilu
* @version 2018-07-25
*/
@Configuration
public class CORSConfiguration {
@Bean
public WebMvcConfigurer corsConfigurer() {
return new WebMvcConfigurerAdapter() {
@Override
public void addCorsMappings(CorsRegistry registry) {
registry.addMapping("/**")
.allowedHeaders("*")
.allowedMethods("*")
.allowedOrigins("*");
}
};
}
}
\ No newline at end of file
package cn.enilu.flash.api.config;
import net.sf.ehcache.CacheManager;
import org.springframework.cache.annotation.EnableCaching;
import org.springframework.cache.ehcache.EhCacheCacheManager;
import org.springframework.cache.ehcache.EhCacheManagerFactoryBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.io.ClassPathResource;
/**
* 加载ehcache缓存配置<br>
* @version 2018-07-24
*
* @author enilu
*
*/
@Configuration
@EnableCaching
public class EhCacheConfig {
@Bean
public EhCacheCacheManager cacheManager(CacheManager cacheManager) {
return new EhCacheCacheManager(cacheManager);
}
@Bean
public EhCacheManagerFactoryBean ehcache() {
EhCacheManagerFactoryBean ehCacheManagerFactoryBean = new EhCacheManagerFactoryBean();
ehCacheManagerFactoryBean.setConfigLocation(new ClassPathResource("ehcache.xml"));
return ehCacheManagerFactoryBean;
}
}
package cn.enilu.flash.api.config;
import cn.enilu.flash.security.ApiRealm;
import cn.enilu.flash.security.JwtFilter;
import cn.enilu.flash.security.SystemLogoutFilter;
import cn.enilu.flash.utils.Maps;
import org.apache.shiro.mgt.DefaultSessionStorageEvaluator;
import org.apache.shiro.mgt.DefaultSubjectDAO;
import org.apache.shiro.spring.LifecycleBeanPostProcessor;
import org.apache.shiro.spring.security.interceptor.AuthorizationAttributeSourceAdvisor;
import org.apache.shiro.spring.web.ShiroFilterFactoryBean;
import org.apache.shiro.web.mgt.DefaultWebSecurityManager;
import org.springframework.aop.framework.autoproxy.DefaultAdvisorAutoProxyCreator;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.DependsOn;
import org.springframework.context.annotation.Lazy;
import javax.servlet.Filter;
import java.util.LinkedHashMap;
import java.util.Map;
/**
* @author :enilu
* @date :Created in 2019/7/30 23:08
*/
@Configuration
public class ShiroConfig {
@Bean("securityManager")
public DefaultWebSecurityManager getManager(ApiRealm realm) {
DefaultWebSecurityManager manager = new DefaultWebSecurityManager();
// 使用自己的realm
manager.setRealm(realm);
/*
* 关闭shiro自带的session,详情见文档
* http://shiro.apache.org/session-management.html#SessionManagement-StatelessApplications%28Sessionless%29
*/
DefaultSubjectDAO subjectDAO = new DefaultSubjectDAO();
DefaultSessionStorageEvaluator defaultSessionStorageEvaluator = new DefaultSessionStorageEvaluator();
defaultSessionStorageEvaluator.setSessionStorageEnabled(false);
subjectDAO.setSessionStorageEvaluator(defaultSessionStorageEvaluator);
manager.setSubjectDAO(subjectDAO);
return manager;
}
@Bean("shiroFilter")
public ShiroFilterFactoryBean factory(DefaultWebSecurityManager securityManager) {
ShiroFilterFactoryBean factoryBean = new ShiroFilterFactoryBean();
// 添加自己的过滤器并且取名为jwt
Map<String, Filter> filterMap = Maps.newHashMap();
filterMap.put("jwt", new JwtFilter());
factoryBean.setFilters(filterMap);
factoryBean.setSecurityManager(securityManager);
factoryBean.setUnauthorizedUrl("/401");
filterMap.put("logout", new SystemLogoutFilter());
Map<String, String> filterRuleMap = new LinkedHashMap<String,String>();
filterRuleMap.put("/account/**","anon");
//swagger资源不拦截
filterRuleMap.put("/swagger-ui.html","anon");
filterRuleMap.put("/v2/api-docs/**", "anon");
filterRuleMap.put("/webjars/**", "anon");
filterRuleMap.put("/swagger-resources","anon");
filterRuleMap.put("/images/**","anon");
filterRuleMap.put("/configuration/security","anon");
filterRuleMap.put("/configuration/ui","anon");
//druid监控地址不拦截
filterRuleMap.put("/druid/**","anon");
//系统图片资源不拦截
filterRuleMap.put("/file/getImgStream","anon");
filterRuleMap.put("/file/download","anon");
filterRuleMap.put("/account/logout", "logout");
filterRuleMap.put("/401", "anon");
filterRuleMap.put("/**", "jwt");
factoryBean.setFilterChainDefinitionMap(filterRuleMap);
return factoryBean;
}
/**
* 下面的代码是添加注解支持
*/
@Bean
@DependsOn("lifecycleBeanPostProcessor")
public DefaultAdvisorAutoProxyCreator defaultAdvisorAutoProxyCreator() {
DefaultAdvisorAutoProxyCreator defaultAdvisorAutoProxyCreator = new DefaultAdvisorAutoProxyCreator();
// 强制使用cglib,防止重复代理和可能引起代理出错的问题
// https://zhuanlan.zhihu.com/p/29161098
defaultAdvisorAutoProxyCreator.setProxyTargetClass(true);
return defaultAdvisorAutoProxyCreator;
}
@Bean
public LifecycleBeanPostProcessor lifecycleBeanPostProcessor() {
return new LifecycleBeanPostProcessor();
}
@Bean
public AuthorizationAttributeSourceAdvisor authorizationAttributeSourceAdvisor(DefaultWebSecurityManager securityManager) {
AuthorizationAttributeSourceAdvisor advisor = new AuthorizationAttributeSourceAdvisor();
advisor.setSecurityManager(securityManager);
return advisor;
}
}
package cn.enilu.flash.api.config;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.ParameterBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.schema.ModelRef;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.service.Parameter;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;
import java.util.ArrayList;
import java.util.List;
/**
* swagger在线文档配置<br>
* 项目启动后可通过地址:http://host:ip/swagger-ui.html 查看在线文档
* @version 2018-07-24
*
* @author enilu
*/
@Configuration
@EnableSwagger2
public class Swagger2Configuration {
@Bean
public Docket createRestApi() {
//添加head参数start
ParameterBuilder tokenPar = new ParameterBuilder();
List<Parameter> pars = new ArrayList<Parameter>();
tokenPar.name("Authorization").description("Token").modelRef(new ModelRef("string")).parameterType("header").required(false).build();
pars.add(tokenPar.build());
//添加head参数end
return new Docket(DocumentationType.SWAGGER_2)
.apiInfo(apiInfo())
.select()
.apis(RequestHandlerSelectors.basePackage("cn.enilu.flash.api.controller"))
.paths(PathSelectors.any())
.build().globalOperationParameters(pars);
}
private ApiInfo apiInfo() {
return new ApiInfoBuilder()
.title("linjiashop api")
.description("简洁,快捷的店铺系统")
.termsOfServiceUrl("http://micorapp.store")
.contact("blog.enilu.cn")
.version("1.0")
.build();
}
}
package cn.enilu.flash.api.config;
import cn.enilu.flash.security.JwtUtil;
import cn.enilu.flash.utils.Constants;
import cn.enilu.flash.utils.HttpUtil;
import cn.enilu.flash.utils.StringUtil;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.domain.AuditorAware;
import java.util.Optional;
/**
* 审计功能配置
*
* @author enilu
* @version 2019/1/8 0008
*/
@Configuration
public class UserIDAuditorConfig implements AuditorAware<Long> {
@Override
public Optional<Long> getCurrentAuditor() {
try {
String token = HttpUtil.getRequest().getHeader("Authorization");
if (StringUtil.isNotEmpty(token)) {
return Optional.of(JwtUtil.getUserId(token));
}
}catch (Exception e){
//返回系统用户id
return Optional.of(Constants.SYSTEM_USER_ID);
}
//返回系统用户id
return Optional.of(Constants.SYSTEM_USER_ID);
}
}
package cn.enilu.flash.api.controller;
import cn.enilu.flash.bean.core.AuthorizationUser;
import cn.enilu.flash.bean.entity.system.User;
import cn.enilu.flash.bean.vo.JwtUser;
import cn.enilu.flash.bean.vo.front.Rets;
import cn.enilu.flash.cache.CacheDao;
import cn.enilu.flash.core.log.LogManager;
import cn.enilu.flash.core.log.LogTaskFactory;
import cn.enilu.flash.security.UserService;
import cn.enilu.flash.service.system.AccountService;
import cn.enilu.flash.service.system.ManagerService;
import cn.enilu.flash.utils.HttpUtil;
import cn.enilu.flash.utils.MD5;
import cn.enilu.flash.utils.Maps;
import cn.enilu.flash.utils.StringUtil;
import cn.enilu.flash.web.controller.BaseController;
import org.nutz.mapl.Mapl;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import javax.servlet.http.HttpServletRequest;
import java.util.HashMap;
import java.util.Map;
/**
* AccountController
*
* @author enilu
* @version 2018/9/12 0012
*/
@RestController
@RequestMapping("/account")
public class AccountController extends BaseController {
private Logger logger = LoggerFactory.getLogger(AccountController.class);
@Value("${jwt.token.expire.time}")
private Long tokenExpireTime ;
@Autowired
private ManagerService managerService;
@Autowired
private AccountService accountService;
@Autowired
private UserService userService;
@Autowired
private CacheDao cacheDao;
/**
* 用户登录<br>
* 1,验证没有注册<br>
* 2,验证密码错误<br>
* 3,登录成功
* @param userName
* @param password
* @return
*/
@RequestMapping(value = "/login",method = RequestMethod.POST)
public Object login(@RequestParam("username") String userName,
@RequestParam("password") String password){
try {
logger.info("用户登录:" + userName + ",密码:" + password);
//1,
User user = managerService.findByAccount(userName);
if (user == null) {
return Rets.failure("该用户不存在");
}
String passwdMd5 = MD5.md5(password, user.getSalt());
//2,
if (!user.getPassword().equals(passwdMd5)) {
return Rets.failure("输入的密码错误");
}
String token = userService.loginForToken(new JwtUser(user));
Map<String, String> result = new HashMap<>(1);
logger.info("token:{}",token);
result.put("token", token);
LogManager.me().executeLog(LogTaskFactory.loginLog(user.getId(), HttpUtil.getIp()));
return Rets.success(result);
} catch (Exception e) {
logger.error(e.getMessage(), e);
}
return Rets.failure("登录时失败");
}
/**
* 退出登录
* @return
*/
@RequestMapping(value = "/logout",method = RequestMethod.POST)
public Object logout(){
HttpServletRequest request = HttpUtil.getRequest();
String token = this.getToken(HttpUtil.getRequest());
accountService.logout(token);
Long idUser = getIdUser(request);
LogManager.me().executeLog(LogTaskFactory.exitLog(idUser, HttpUtil.getIp()));
return Rets.success();
}
@RequestMapping(value = "/info",method = RequestMethod.GET)
public Object info( ){
HttpServletRequest request = HttpUtil.getRequest();
Long idUser = null;
try {
idUser = getIdUser(request);
}catch (Exception e){
return Rets.expire();
}
if(idUser!=null){
User user = managerService.get(idUser);
if(StringUtil.isEmpty(user.getRoleid())){
return Rets.failure("该用户未配置权限");
}
AuthorizationUser shiroUser = UserService.me().getAuthorizationInfo(user.getAccount());
Map map = Maps.newHashMap("name",user.getName(),"role","admin","roles", shiroUser.getRoleCodes());
map.put("permissions",shiroUser.getUrls());
Map profile = (Map) Mapl.toMaplist(user);
profile.put("dept",shiroUser.getDeptName());
profile.put("roles",shiroUser.getRoleNames());
map.put("profile",profile);
return Rets.success(map);
}
return Rets.failure("获取用户信息失败");
}
@RequestMapping(value = "/updatePwd",method = RequestMethod.POST)
public Object updatePwd( String oldPassword,String password, String rePassword){
try {
User user = managerService.get(getIdUser(HttpUtil.getRequest()));
logger.info("oldPassword:{},password:{},rePassword:{}",MD5.md5(oldPassword, user.getSalt()),password,rePassword);
if(!MD5.md5(oldPassword, user.getSalt()).equals(user.getPassword())){
return Rets.failure("旧密码输入错误");
}
if(!password.equals(rePassword)){
return Rets.failure("新密码前后不一致");
}
user.setPassword(MD5.md5(password, user.getSalt()));
managerService.update(user);
//清空缓存
cacheDao.hset(CacheDao.SESSION,user.getAccount(),null);
return Rets.success();
} catch (Exception e) {
logger.error(e.getMessage(), e);
}
return Rets.failure("更改密码失败");
}
}
package cn.enilu.flash.api.controller;
import cn.enilu.flash.bean.vo.front.Rets;
import cn.enilu.flash.service.dashboard.DashboardService;
import cn.enilu.flash.web.controller.BaseController;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
import java.util.Map;
/**
* @author :enilu
* @date :Created in 1/7/2020 2:23 PM
*/
@RequestMapping("/dashboard")
@RestController
public class DashboardController extends BaseController {
@Autowired
private DashboardService dashboardService;
@RequestMapping(method = RequestMethod.GET)
public Object get(){
Map data = dashboardService.getDashboardData();
return Rets.success(data);
}
}
package cn.enilu.flash.api.controller;
import cn.enilu.flash.bean.entity.system.FileInfo;
import cn.enilu.flash.bean.enumeration.Permission;
import cn.enilu.flash.bean.vo.front.Rets;
import cn.enilu.flash.service.system.FileService;
import cn.enilu.flash.utils.CryptUtil;
import cn.enilu.flash.utils.HttpUtil;
import cn.enilu.flash.utils.Maps;
import cn.enilu.flash.utils.StringUtil;
import cn.enilu.flash.web.controller.BaseController;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import javax.servlet.http.HttpServletResponse;
import java.io.*;
@RestController
@RequestMapping("/file")
public class FileController extends BaseController {
@Autowired
private static final Logger logger = LoggerFactory.getLogger(FileController.class);
@Autowired
private FileService fileService;
/**
* 上传文件
* @param multipartFile
* @return
*/
@RequestMapping(method = RequestMethod.POST)
@RequiresPermissions(value = {Permission.FILE_UPLOAD})
public Object upload(@RequestPart("file") MultipartFile multipartFile) {
try {
FileInfo fileInfo = fileService.upload(multipartFile);
return Rets.success(fileInfo);
} catch (Exception e) {
logger.error("上传文件异常",e);
return Rets.failure("上传文件失败");
}
}
/**
* 下载文件
* @param fileName
* @param fileName
*/
@RequestMapping(value="download",method = RequestMethod.GET)
public void download(@RequestParam(value = "fileName",required = false) String fileName,
@RequestParam(value = "idFile",required = false) Long idFile){
FileInfo fileInfo = null;
if(StringUtil.isNotEmpty(fileName)) {
fileInfo = fileService.getByName(fileName);
}
if(idFile!=null){
fileInfo = fileService.get(idFile);
}
downloadFile(fileInfo);
}
public void downloadFile(FileInfo fileInfo){
String fileName = fileInfo.getOriginalFileName();
HttpServletResponse response = HttpUtil.getResponse();
response.setContentType("application/x-download");
try {
fileName = new String(fileName.getBytes(), "ISO-8859-1");
response.setHeader("Content-Disposition", "attachment;filename=" + fileName);
}catch (Exception e){
e.printStackTrace();
}
int length = 1024;
byte[] buffer = new byte[length];
FileInputStream fis = null;
BufferedInputStream bis = null;
OutputStream os = null;
try {
File file = new File(fileInfo.getAblatePath());
os = response.getOutputStream();
fis = new FileInputStream(file);
bis = new BufferedInputStream(fis);
int i = bis.read(buffer);
while(i != -1){
os.write(buffer);
buffer = new byte[length];
i = bis.read(buffer);
}
} catch (Exception e) {
logger.error("download error",e);
}finally {
try {
bis.close();
fis.close();
} catch (IOException e) {
logger.error("close inputstream error", e);
}
}
}
/**
* 获取base64图片数据
* @param fileName
* @return
*/
@RequestMapping(value="getImgBase64",method = RequestMethod.GET)
public Object getImgBase64(@RequestParam("idFile")String fileName ){
FileInfo fileInfo = fileService.getByName(fileName);
FileInputStream fis = null;
try {
File file = new File(fileInfo.getAblatePath());
byte[] bytes = new byte[(int) file.length()];
fis = new FileInputStream(file);
BufferedInputStream bis = new BufferedInputStream(fis);
bis.read(bytes);
String base64 = CryptUtil.encodeBASE64(bytes);
return Rets.success(Maps.newHashMap("imgContent", base64));
} catch (Exception e) {
logger.error("get img error",e);
return Rets.failure("获取图片异常");
}finally{
try {
fis.close();
}catch (Exception e){
logger.error("close getImgBase64 error",e);
}
}
}
/**
* 获取图片流
* @param response
* @param fileName
*/
@RequestMapping(value="getImgStream",method = RequestMethod.GET)
public void getImgStream(HttpServletResponse response,
@RequestParam("idFile")String fileName){
FileInfo fileInfo = fileService.getByName(fileName);
FileInputStream fis = null;
response.setContentType("image/"+fileInfo.getRealFileName().split("\\.")[1]);
try {
OutputStream out = response.getOutputStream();
File file = new File(fileInfo.getAblatePath());
fis = new FileInputStream(file);
byte[] b = new byte[fis.available()];
fis.read(b);
out.write(b);
out.flush();
} catch (Exception e) {
logger.error("getImgStream error",e);
} finally {
if (fis != null) {
try {
fis.close();
} catch (IOException e) {
logger.error("close getImgStream error",e);
}
}
}
}
}
package cn.enilu.flash.api.controller.cms;
import cn.enilu.flash.web.controller.BaseController;
import cn.enilu.flash.bean.constant.factory.PageFactory;
import cn.enilu.flash.bean.core.BussinessLog;
import cn.enilu.flash.bean.entity.cms.Article;
import cn.enilu.flash.bean.enumeration.Permission;
import cn.enilu.flash.bean.vo.front.Rets;
import cn.enilu.flash.bean.vo.query.SearchFilter;
import cn.enilu.flash.service.cms.ArticleService;
import cn.enilu.flash.utils.DateUtil;
import cn.enilu.flash.utils.factory.Page;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.repository.query.Param;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
/**
* 文章管理
*/
@RestController
@RequestMapping("/article")
public class ArticleMgrController extends BaseController {
@Autowired
private ArticleService articleService;
@RequestMapping(method = RequestMethod.POST)
@BussinessLog(value = "编辑文章",key="name")
@RequiresPermissions(value = {Permission.ARTICLE_EDIT})
public Object save(){
Article article = getFromJson(Article.class);
if(article.getId()!=null){
Article old = articleService.get(article.getId());
old.setAuthor(article.getAuthor());
old.setContent(article.getContent());
old.setIdChannel(article.getIdChannel());
old.setImg(article.getImg());
old.setTitle(article.getTitle());
articleService.update(old);
}else {
articleService.insert(article);
}
return Rets.success();
}
@RequestMapping(method = RequestMethod.DELETE)
@BussinessLog(value = "删除文章",key="id")
@RequiresPermissions(value = {Permission.ARTICLE_DEL})
public Object remove(Long id){
articleService.deleteById(id);
return Rets.success();
}
@RequestMapping(method = RequestMethod.GET)
@RequiresPermissions(value = {Permission.ARTICLE})
public Object get(@Param("id") Long id) {
Article article = articleService.get(id);
return Rets.success(article);
}
@RequestMapping(value = "/list",method = RequestMethod.GET)
@RequiresPermissions(value = {Permission.ARTICLE})
public Object list(@RequestParam(required = false) String title,
@RequestParam(required = false) String author,
@RequestParam(required = false) String startDate,
@RequestParam(required = false) String endDate
) {
Page<Article> page = new PageFactory<Article>().defaultPage();
page.addFilter("title", SearchFilter.Operator.LIKE,title);
page.addFilter("author", SearchFilter.Operator.EQ,author);
page.addFilter("createTime", SearchFilter.Operator.GTE, DateUtil.parse(startDate,"yyyyMMddHHmmss"));
page.addFilter("createTime", SearchFilter.Operator.LTE, DateUtil.parse(endDate,"yyyyMMddHHmmss"));
page = articleService.queryPage(page);
return Rets.success(page);
}
}
package cn.enilu.flash.api.controller.cms;
import cn.enilu.flash.utils.JsonUtil;
import cn.enilu.flash.web.controller.BaseController;
import cn.enilu.flash.bean.core.BussinessLog;
import cn.enilu.flash.bean.entity.cms.Banner;
import cn.enilu.flash.bean.enumeration.Permission;
import cn.enilu.flash.bean.vo.front.Rets;
import cn.enilu.flash.bean.vo.query.SearchFilter;
import cn.enilu.flash.service.cms.BannerService;
import cn.enilu.flash.utils.StringUtil;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import javax.validation.Valid;
import java.util.List;
/**
* banner管理
*/
@RestController
@RequestMapping("/banner")
public class BannerMgrController extends BaseController {
@Autowired
private BannerService bannerService;
@RequestMapping(method = RequestMethod.POST)
@BussinessLog(value = "编辑banner", key = "title")
@RequiresPermissions(value = {Permission.BANNER_EDIT})
public Object save(@ModelAttribute @Valid Banner banner) {
if(StringUtil.isNotEmpty(banner.getParam())){
if(!JsonUtil.isJson(banner.getParam())){
return Rets.failure("参数必须为json格式");
}
}
if(banner.getId()==null){
bannerService.insert(banner);
}else {
bannerService.update(banner);
}
return Rets.success();
}
@RequestMapping(method = RequestMethod.DELETE)
@BussinessLog(value = "删除banner", key = "id")
@RequiresPermissions(value = {Permission.BANNER_DEL})
public Object remove(Long id) {
bannerService.deleteById(id);
return Rets.success();
}
@RequestMapping(value = "/list", method = RequestMethod.GET)
@RequiresPermissions(value = {Permission.BANNER})
public Object list(@RequestParam(required = false) String title) {
SearchFilter filter = null;
if(StringUtil.isNotEmpty(title)){
filter = SearchFilter.build("title", SearchFilter.Operator.LIKE,title);
}
List<Banner> list = bannerService.queryAll(filter);
return Rets.success(list);
}
}
package cn.enilu.flash.api.controller.cms;
import cn.enilu.flash.web.controller.BaseController;
import cn.enilu.flash.bean.core.BussinessLog;
import cn.enilu.flash.bean.entity.cms.Channel;
import cn.enilu.flash.bean.enumeration.Permission;
import cn.enilu.flash.bean.vo.front.Rets;
import cn.enilu.flash.service.cms.ChannelService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
import javax.validation.Valid;
import java.util.List;
/**
* 栏目管理
*/
@RestController
@RequestMapping("/channel")
public class ChannelMgrController extends BaseController {
@Autowired
private ChannelService channelService;
@RequestMapping(method = RequestMethod.POST)
@BussinessLog(value = "编辑栏目", key = "name")
@RequiresPermissions(value = {Permission.CHANNEL_EDIT})
public Object save(@ModelAttribute @Valid Channel channel) {
if(channel.getId()==null) {
channelService.insert(channel);
}else{
channelService.update(channel);
}
return Rets.success();
}
@RequestMapping(method = RequestMethod.DELETE)
@BussinessLog(value = "删除栏目", key = "id")
@RequiresPermissions(value = {Permission.CHANNEL_DEL})
public Object remove(Long id) {
channelService.deleteById(id);
return Rets.success();
}
@RequestMapping(value = "/list", method = RequestMethod.GET)
@RequiresPermissions(value = {Permission.CHANNEL})
public Object list() {
List<Channel> list = channelService.queryAll();
return Rets.success(list);
}
}
package cn.enilu.flash.api.controller.cms;
import cn.enilu.flash.web.controller.BaseController;
import cn.enilu.flash.bean.constant.factory.PageFactory;
import cn.enilu.flash.bean.entity.cms.Contacts;
import cn.enilu.flash.bean.enumeration.Permission;
import cn.enilu.flash.bean.vo.front.Rets;
import cn.enilu.flash.bean.vo.query.SearchFilter;
import cn.enilu.flash.service.cms.ContactsService;
import cn.enilu.flash.utils.DateUtil;
import cn.enilu.flash.utils.factory.Page;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
/**
* 邀约信息管理
*/
@RestController
@RequestMapping("/contacts")
public class ContactsController extends BaseController {
@Autowired
private ContactsService contactsService;
@RequestMapping(value = "/list",method = RequestMethod.GET)
@RequiresPermissions(value = {Permission.CONTACTS})
public Object list(@RequestParam(required = false) String userName,
@RequestParam(required = false) String mobile,
@RequestParam(required = false) String startDate,
@RequestParam(required = false) String endDate
) {
Page<Contacts> page = new PageFactory<Contacts>().defaultPage();
page.addFilter("createTime", SearchFilter.Operator.GTE, DateUtil.parse(startDate,"yyyyMMddHHmmss"));
page.addFilter("createTime", SearchFilter.Operator.LTE, DateUtil.parse(endDate,"yyyyMMddHHmmss"));
page.addFilter("userName", SearchFilter.Operator.EQ,userName);
page.addFilter("mobile", SearchFilter.Operator.EQ,mobile);
page = contactsService.queryPage(page);
return Rets.success(page);
}
}
package cn.enilu.flash.api.controller.cms;
import cn.enilu.flash.web.controller.BaseController;
import cn.enilu.flash.bean.constant.factory.PageFactory;
import cn.enilu.flash.bean.entity.system.FileInfo;
import cn.enilu.flash.bean.enumeration.Permission;
import cn.enilu.flash.bean.vo.front.Rets;
import cn.enilu.flash.bean.vo.query.SearchFilter;
import cn.enilu.flash.service.system.FileService;
import cn.enilu.flash.utils.StringUtil;
import cn.enilu.flash.utils.factory.Page;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
@RestController
@RequestMapping("/fileMgr")
public class FileMgrController extends BaseController {
@Autowired
private FileService fileService;
@RequestMapping(value = "/list", method = RequestMethod.GET)
@RequiresPermissions(value = {Permission.FILE})
public Object list(@RequestParam(required = false) String originalFileName
) {
Page<FileInfo> page = new PageFactory<FileInfo>().defaultPage();
if (StringUtil.isNotEmpty(originalFileName)) {
page.addFilter(SearchFilter.build("originalFileName", SearchFilter.Operator.LIKE, originalFileName));
}
page = fileService.queryPage(page);
return Rets.success(page);
}
}
package cn.enilu.flash.api.controller.front.officialsite;
import cn.enilu.flash.web.controller.BaseController;
import cn.enilu.flash.bean.entity.cms.Article;
import cn.enilu.flash.bean.vo.front.Rets;
import cn.enilu.flash.service.cms.ArticleService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.repository.query.Param;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
@RestController
@RequestMapping("/offcialsite/article")
public class ArticleController extends BaseController {
private Logger logger = LoggerFactory.getLogger(ArticleController.class);
@Autowired
private ArticleService articleService;
@RequestMapping(method = RequestMethod.GET)
public Object get(@Param("id") Long id,@Param("type")String type) {
logger.info("type:{},id:{}",type,id);
Article article = articleService.get(id);
return Rets.success(article);
}
}
package cn.enilu.flash.api.controller.front.officialsite;
import cn.enilu.flash.web.controller.BaseController;
import cn.enilu.flash.bean.entity.cms.Article;
import cn.enilu.flash.bean.enumeration.cms.BannerTypeEnum;
import cn.enilu.flash.bean.enumeration.cms.ChannelEnum;
import cn.enilu.flash.bean.vo.front.Rets;
import cn.enilu.flash.bean.vo.offcialsite.BannerVo;
import cn.enilu.flash.bean.vo.offcialsite.Product;
import cn.enilu.flash.service.cms.ArticleService;
import cn.enilu.flash.service.cms.BannerService;
import cn.enilu.flash.utils.factory.Page;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@RestController
@RequestMapping("/offcialsite/case")
public class CaseController extends BaseController {
@Autowired
private BannerService bannerService;
@Autowired
private ArticleService articleService;
@RequestMapping(method = RequestMethod.GET)
public Object index() {
Map<String, Object> dataMap = new HashMap<>(2);
BannerVo banner = bannerService.queryBanner(BannerTypeEnum.CASE.getValue());
dataMap.put("banner", banner);
List<Product> products = new ArrayList<>();
Page<Article> articlePage = articleService.query(1, 10, ChannelEnum.PRODUCT.getId());
for (Article article : articlePage.getRecords()) {
products.add(new Product(article.getId(), article.getTitle(), article.getImg()));
}
dataMap.put("caseList", products);
Map map = new HashMap(1);
map.put("data", dataMap);
return Rets.success(map);
}
}
package cn.enilu.flash.api.controller.front.officialsite;
import lombok.Data;
import java.util.Date;
@Data
public class Contact {
public String username;
private String email;
private String mobile;
private String description;
private Date createAt;
}
package cn.enilu.flash.api.controller.front.officialsite;
import cn.enilu.flash.web.controller.BaseController;
import cn.enilu.flash.bean.entity.cms.Contacts;
import cn.enilu.flash.bean.vo.front.Rets;
import cn.enilu.flash.service.cms.ContactsService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
import javax.validation.Valid;
@RestController
@RequestMapping("/offcialsite/contact")
public class ContactController extends BaseController {
private Logger logger = LoggerFactory.getLogger(getClass());
@Autowired
private ContactsService contactsService;
@RequestMapping(method = RequestMethod.POST)
public Object save(@Valid Contacts contacts){
contactsService.insert(contacts);
return Rets.success();
}
}
package cn.enilu.flash.api.controller.front.officialsite;
import cn.enilu.flash.web.controller.BaseController;
import cn.enilu.flash.bean.entity.cms.Article;
import cn.enilu.flash.bean.enumeration.cms.BannerTypeEnum;
import cn.enilu.flash.bean.enumeration.cms.ChannelEnum;
import cn.enilu.flash.bean.vo.front.Rets;
import cn.enilu.flash.bean.vo.offcialsite.BannerVo;
import cn.enilu.flash.bean.vo.offcialsite.News;
import cn.enilu.flash.service.cms.ArticleService;
import cn.enilu.flash.service.cms.BannerService;
import cn.enilu.flash.utils.factory.Page;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@RestController
@RequestMapping("/offcialsite/news")
public class NewsController extends BaseController {
@Autowired
private BannerService bannerService;
@Autowired
private ArticleService articleService;
@RequestMapping(method = RequestMethod.GET)
public Object list() {
Map<String, Object> dataMap = new HashMap<>(10);
BannerVo banner = bannerService.queryBanner(BannerTypeEnum.NEWS.getValue());
dataMap.put("banner", banner);
List<News> newsList = new ArrayList<>();
Page<Article> articlePage = articleService.query(1, 10, ChannelEnum.NEWS.getId());
for (cn.enilu.flash.bean.entity.cms.Article article : articlePage.getRecords()) {
News news = new News();
news.setDesc(article.getTitle());
news.setUrl("/article?id=" + article.getId());
news.setSrc("static/images/icon/user.png");
newsList.add(news);
}
dataMap.put("list", newsList);
Map map = new HashMap(2);
map.put("data", dataMap);
return Rets.success(map);
}
}
package cn.enilu.flash.api.controller.front.officialsite;
import cn.enilu.flash.web.controller.BaseController;
import cn.enilu.flash.bean.entity.cms.Article;
import cn.enilu.flash.bean.enumeration.cms.ChannelEnum;
import cn.enilu.flash.bean.vo.front.Rets;
import cn.enilu.flash.bean.vo.offcialsite.BannerVo;
import cn.enilu.flash.bean.vo.offcialsite.News;
import cn.enilu.flash.bean.vo.offcialsite.Product;
import cn.enilu.flash.bean.vo.offcialsite.Solution;
import cn.enilu.flash.service.cms.ArticleService;
import cn.enilu.flash.service.cms.BannerService;
import cn.enilu.flash.utils.Maps;
import cn.enilu.flash.utils.factory.Page;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
@RestController
@RequestMapping("/offcialsite")
public class OffcialSiteController extends BaseController {
@Autowired
private BannerService bannerService;
@Autowired
private ArticleService articleService;
@RequestMapping(method = RequestMethod.GET)
public Object index() {
Map<String, Object> dataMap = Maps.newHashMap();
BannerVo banner = bannerService.queryIndexBanner();
dataMap.put("banner", banner);
List<News> newsList = new ArrayList<>();
List<cn.enilu.flash.bean.entity.cms.Article> articles = articleService.queryIndexNews();
for (cn.enilu.flash.bean.entity.cms.Article article : articles) {
News news = new News();
news.setDesc(article.getTitle());
news.setUrl("/article?id=" + article.getId());
news.setSrc("static/images/icon/user.png");
newsList.add(news);
}
dataMap.put("newsList", newsList);
List<Product> products = new ArrayList<>();
Page<Article> articlePage = articleService.query(1, 4, ChannelEnum.PRODUCT.getId());
for (Article article : articlePage.getRecords()) {
Product product = new Product();
product.setId(article.getId());
product.setName(article.getTitle());
product.setImg(article.getImg());
products.add(product);
}
dataMap.put("productList", products);
List<Solution> solutions = new ArrayList<>();
articlePage = articleService.query(1, 4, ChannelEnum.SOLUTION.getId());
for (Article article : articlePage.getRecords()) {
Solution solution = new Solution();
solution.setId(article.getId());
solution.setName(article.getTitle());
solution.setImg(article.getImg());
solutions.add(solution);
}
dataMap.put("solutionList", solutions);
Map map = Maps.newHashMap("data",dataMap);
return Rets.success(map);
}
}
package cn.enilu.flash.api.controller.front.officialsite;
import cn.enilu.flash.web.controller.BaseController;
import cn.enilu.flash.bean.entity.cms.Article;
import cn.enilu.flash.bean.enumeration.cms.BannerTypeEnum;
import cn.enilu.flash.bean.enumeration.cms.ChannelEnum;
import cn.enilu.flash.bean.vo.front.Rets;
import cn.enilu.flash.bean.vo.offcialsite.BannerVo;
import cn.enilu.flash.bean.vo.offcialsite.Product;
import cn.enilu.flash.service.cms.ArticleService;
import cn.enilu.flash.service.cms.BannerService;
import cn.enilu.flash.utils.Maps;
import cn.enilu.flash.utils.factory.Page;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
@RestController
@RequestMapping("/offcialsite/product")
public class OffcialSiteProductController extends BaseController {
@Autowired
private BannerService bannerService;
@Autowired
private ArticleService articleService;
@RequestMapping(method = RequestMethod.GET)
public Object index() {
Map<String, Object> dataMap = Maps.newHashMap();
BannerVo banner = bannerService.queryBanner(BannerTypeEnum.SOLUTION.getValue());
dataMap.put("banner", banner);
List<Product> products = new ArrayList<>();
Page<Article> articlePage = articleService.query(1, 10, ChannelEnum.PRODUCT.getId());
for (Article article : articlePage.getRecords()) {
products.add(new Product(article.getId(), article.getTitle(), article.getImg()));
}
dataMap.put("productList", products);
Map map = Maps.newHashMap("data",dataMap);
return Rets.success(map);
}
}
package cn.enilu.flash.api.controller.front.officialsite;
import cn.enilu.flash.web.controller.BaseController;
import cn.enilu.flash.bean.entity.cms.Article;
import cn.enilu.flash.bean.enumeration.cms.BannerTypeEnum;
import cn.enilu.flash.bean.enumeration.cms.ChannelEnum;
import cn.enilu.flash.bean.vo.front.Rets;
import cn.enilu.flash.bean.vo.offcialsite.BannerVo;
import cn.enilu.flash.bean.vo.offcialsite.Solution;
import cn.enilu.flash.service.cms.ArticleService;
import cn.enilu.flash.service.cms.BannerService;
import cn.enilu.flash.utils.Maps;
import cn.enilu.flash.utils.factory.Page;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
@RestController
@RequestMapping("/offcialsite/solution")
public class SolutionController extends BaseController {
@Autowired
private BannerService bannerService;
@Autowired
private ArticleService articleService;
@RequestMapping(method = RequestMethod.GET)
public Object index() {
Map<String, Object> dataMap = Maps.newHashMap();
BannerVo banner = bannerService.queryBanner(BannerTypeEnum.SOLUTION.getValue());
dataMap.put("banner", banner);
List<Solution> solutions = new ArrayList<>();
Page<Article> articlePage = articleService.query(1, 10, ChannelEnum.SOLUTION.getId());
for (Article article : articlePage.getRecords()) {
solutions.add(new Solution(article.getId(), article.getTitle(), article.getImg()));
}
dataMap.put("solutionList", solutions);
Map map = Maps.newHashMap("data",dataMap);
return Rets.success(map);
}
}
package cn.enilu.flash.api.controller.message;
import cn.enilu.flash.bean.constant.factory.PageFactory;
import cn.enilu.flash.bean.core.BussinessLog;
import cn.enilu.flash.bean.entity.message.Message;
import cn.enilu.flash.bean.enumeration.Permission;
import cn.enilu.flash.bean.vo.front.Rets;
import cn.enilu.flash.bean.vo.query.SearchFilter;
import cn.enilu.flash.service.message.MessageService;
import cn.enilu.flash.utils.DateUtil;
import cn.enilu.flash.utils.factory.Page;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
@RestController
@RequestMapping("/message")
public class MessageController {
@Autowired
private MessageService messageService;
@RequestMapping(value = "/list", method = RequestMethod.GET)
@RequiresPermissions(value = {Permission.MSG})
public Object list( @RequestParam(required = false) String startDate,
@RequestParam(required = false) String endDate) {
Page<Message> page = new PageFactory<Message>().defaultPage();
page.addFilter("createTime", SearchFilter.Operator.GTE, DateUtil.parse(startDate,"yyyyMMddHHmmss"));
page.addFilter("createTime", SearchFilter.Operator.LTE, DateUtil.parse(endDate,"yyyyMMddHHmmss"));
page = messageService.queryPage(page);
page.setRecords(page.getRecords());
return Rets.success(page);
}
@RequestMapping(method = RequestMethod.DELETE)
@BussinessLog(value = "清空所有历史消息")
@RequiresPermissions(value = {Permission.MSG_CLEAR})
public Object clear() {
messageService.clear();
return Rets.success();
}
}
\ No newline at end of file
package cn.enilu.flash.api.controller.message;
import cn.enilu.flash.bean.constant.factory.PageFactory;
import cn.enilu.flash.bean.core.BussinessLog;
import cn.enilu.flash.bean.entity.message.MessageSender;
import cn.enilu.flash.bean.enumeration.Permission;
import cn.enilu.flash.bean.vo.front.Rets;
import cn.enilu.flash.service.message.MessagesenderService;
import cn.enilu.flash.utils.factory.Page;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
import javax.validation.Valid;
@RestController
@RequestMapping("/message/sender")
public class MessagesenderController {
@Autowired
private MessagesenderService messagesenderService;
@RequestMapping(value = "/list", method = RequestMethod.GET)
@RequiresPermissions(value = {Permission.MSG_SENDER})
public Object list() {
Page<MessageSender> page = new PageFactory<MessageSender>().defaultPage();
page = messagesenderService.queryPage(page);
page.setRecords(page.getRecords());
return Rets.success(page);
}
@RequestMapping(value = "/queryAll", method = RequestMethod.GET)
@RequiresPermissions(value = {Permission.MSG_SENDER})
public Object queryAll() {
return Rets.success(messagesenderService.queryAll());
}
@RequestMapping(method = RequestMethod.POST)
@BussinessLog(value = "编辑消息发送者", key = "name")
@RequiresPermissions(value = {Permission.MSG_SENDER_EDIT})
public Object save(@ModelAttribute @Valid MessageSender messageSender) {
if(messageSender.getId()!=null){
MessageSender old = messagesenderService.get(messageSender.getId());
}
messagesenderService.save(messageSender);
return Rets.success();
}
@RequestMapping(method = RequestMethod.DELETE)
@BussinessLog(value = "删除消息发送者", key = "id")
@RequiresPermissions(value = {Permission.MSG_SENDER_DEL})
public Object remove(Long id) {
try {
messagesenderService.deleteById(id);
return Rets.success();
} catch (Exception e) {
return Rets.failure(e.getMessage());
}
}
}
package cn.enilu.flash.api.controller.message;
import cn.enilu.flash.bean.constant.factory.PageFactory;
import cn.enilu.flash.bean.core.BussinessLog;
import cn.enilu.flash.bean.entity.message.MessageTemplate;
import cn.enilu.flash.bean.enumeration.Permission;
import cn.enilu.flash.bean.exception.ApplicationException;
import cn.enilu.flash.bean.exception.ApplicationExceptionEnum;
import cn.enilu.flash.bean.vo.front.Rets;
import cn.enilu.flash.service.message.MessagetemplateService;
import cn.enilu.flash.utils.factory.Page;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
import javax.validation.Valid;
@RestController
@RequestMapping("/message/template")
public class MessagetemplateController {
@Autowired
private MessagetemplateService messagetemplateService;
@RequestMapping(value = "/list", method = RequestMethod.GET)
@RequiresPermissions(value = {Permission.MSG_TPL})
public Object list() {
Page<MessageTemplate> page = new PageFactory<MessageTemplate>().defaultPage();
page = messagetemplateService.queryPage(page);
page.setRecords(page.getRecords());
return Rets.success(page);
}
@RequestMapping(method = RequestMethod.POST)
@BussinessLog(value = "编辑消息模板", key = "name")
@RequiresPermissions(value = {Permission.MSG_TPL_EDIT})
public Object save(@ModelAttribute @Valid MessageTemplate messageTemplate) {
if(messageTemplate.getId()==null){
messagetemplateService.insert(messageTemplate);
}else {
messagetemplateService.update(messageTemplate);
}
return Rets.success();
}
@RequestMapping(method = RequestMethod.DELETE)
@BussinessLog(value = "删除消息模板", key = "id")
@RequiresPermissions(value = {Permission.MSG_TPL_DEL})
public Object remove(Long id) {
if (id == null) {
throw new ApplicationException(ApplicationExceptionEnum.REQUEST_NULL);
}
messagetemplateService.deleteById(id);
return Rets.success();
}
}
/**
* @author :enilu
* @date :Created in 2019/10/28 13:52
*/
package cn.enilu.flash.api.controller.mobile;
\ No newline at end of file
/**
* package-info
*
* @version 2018/9/12 0012
* @author enilu
*/
package cn.enilu.flash.api.controller;
\ No newline at end of file
package cn.enilu.flash.api.controller.promotion;
import cn.enilu.flash.bean.constant.factory.PageFactory;
import cn.enilu.flash.bean.core.BussinessLog;
import cn.enilu.flash.bean.entity.promotion.Topic;
import cn.enilu.flash.bean.enumeration.Permission;
import cn.enilu.flash.bean.exception.ApplicationException;
import cn.enilu.flash.bean.exception.ApplicationExceptionEnum;
import cn.enilu.flash.bean.vo.front.Rets;
import cn.enilu.flash.bean.vo.query.SearchFilter;
import cn.enilu.flash.service.promotion.TopicService;
import cn.enilu.flash.utils.DateUtil;
import cn.enilu.flash.utils.StringUtil;
import cn.enilu.flash.utils.factory.Page;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
@RestController
@RequestMapping("/promotion/topic")
public class TopicController {
private Logger logger = LoggerFactory.getLogger(getClass());
@Autowired
private TopicService topicService;
@RequestMapping(value = "/list",method = RequestMethod.GET)
public Object list(@RequestParam(value = "disabled",required = false) Boolean disabled,
@RequestParam(value = "startDate",required = false) String startDate,
@RequestParam(value = "endDate",required = false) String endDate) {
Page<Topic> page = new PageFactory<Topic>().defaultPage();
page.addFilter( "disabled", disabled);
page.addFilter("createTime", SearchFilter.Operator.GTE, DateUtil.parse(startDate,"yyyyMMddHHmmss"));
page.addFilter("createTime", SearchFilter.Operator.LTE, DateUtil.parse(endDate,"yyyyMMddHHmmss"));
page = topicService.queryPage(page);
return Rets.success(page);
}
@RequestMapping(method = RequestMethod.POST)
@BussinessLog(value = "编辑专题", key = "name")
@RequiresPermissions(value = {Permission.TOPIC_EDIT})
public Object save(@ModelAttribute Topic topic){
if(topic.getId()==null){
topic.setPv(0L);
topicService.insert(topic);
}else {
topicService.update(topic);
}
return Rets.success();
}
@RequestMapping(method = RequestMethod.DELETE)
@BussinessLog(value = "删除专题", key = "id")
@RequiresPermissions(value = {Permission.TOPIC_DEL})
public Object remove(Long id){
if (StringUtil.isEmpty(id)) {
throw new ApplicationException(ApplicationExceptionEnum.REQUEST_NULL);
}
topicService.deleteById(id);
return Rets.success();
}
@RequestMapping(value="/changeDisabled",method = RequestMethod.POST)
@RequiresPermissions(value = {Permission.TOPIC_EDIT})
public Object changeIsOnSale(@RequestParam("id") Long id,@RequestParam("disabled") Boolean disabled){
if (id == null) {
throw new ApplicationException(ApplicationExceptionEnum.REQUEST_NULL);
}
topicService.changeDisabled(id,disabled);
return Rets.success();
}
}
package cn.enilu.flash.api.controller.shop;
import cn.enilu.flash.bean.constant.factory.PageFactory;
import cn.enilu.flash.bean.entity.shop.Address;
import cn.enilu.flash.bean.vo.front.Rets;
import cn.enilu.flash.service.shop.AddressService;
import cn.enilu.flash.utils.factory.Page;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
@RestController
@RequestMapping("/shop/address")
public class AddressController {
private Logger logger = LoggerFactory.getLogger(getClass());
@Autowired
private AddressService addressService;
@RequestMapping(value = "/list",method = RequestMethod.GET)
public Object list(@RequestParam(required = false)Long idUser) {
Page<Address> page = new PageFactory<Address>().defaultPage();
page.addFilter("idUser",idUser);
page = addressService.queryPage(page);
return Rets.success(page);
}
}
package cn.enilu.flash.api.controller.shop;
import cn.enilu.flash.bean.constant.factory.PageFactory;
import cn.enilu.flash.bean.core.BussinessLog;
import cn.enilu.flash.bean.entity.shop.AttrKey;
import cn.enilu.flash.bean.exception.ApplicationException;
import cn.enilu.flash.bean.exception.ApplicationExceptionEnum;
import cn.enilu.flash.bean.vo.front.Rets;
import cn.enilu.flash.service.shop.AttrKeyService;
import cn.enilu.flash.utils.StringUtil;
import cn.enilu.flash.utils.factory.Page;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
@RestController
@RequestMapping("/shop/goods/attr/key")
public class AttrKeyController {
private Logger logger = LoggerFactory.getLogger(getClass());
@Autowired
private AttrKeyService attrKeyService;
@RequestMapping(value = "/list",method = RequestMethod.GET)
public Object list() {
Page<AttrKey> page = new PageFactory<AttrKey>().defaultPage();
page = attrKeyService.queryPage(page);
return Rets.success(page);
}
@RequestMapping(method = RequestMethod.POST)
@BussinessLog(value = "编辑商品属性名", key = "name")
public Object save(@ModelAttribute AttrKey tShopGoodsAttrKey){
if(tShopGoodsAttrKey.getId()==null){
attrKeyService.insert(tShopGoodsAttrKey);
}else {
attrKeyService.update(tShopGoodsAttrKey);
}
return Rets.success();
}
@RequestMapping(method = RequestMethod.DELETE)
@BussinessLog(value = "删除商品属性名", key = "id")
public Object remove(Long id){
if (StringUtil.isEmpty(id)) {
throw new ApplicationException(ApplicationExceptionEnum.REQUEST_NULL);
}
AttrKey attrKey = attrKeyService.get(id);
if(!attrKey.getAttrVals().isEmpty()){
throw new ApplicationException(ApplicationExceptionEnum.DATA_CANNOT_REMOVE);
}
attrKeyService.deleteById(id);
return Rets.success();
}
@RequestMapping(value="updateAttrName",method = RequestMethod.POST)
@BussinessLog(value = "修改商品属性名", key = "id")
public Object updateAttrName(@RequestParam("id") Long id,@RequestParam("attrName") String attrName){
if (StringUtil.isEmpty(id)) {
throw new ApplicationException(ApplicationExceptionEnum.REQUEST_NULL);
}
AttrKey attrKey = attrKeyService.get(id);
attrKey.setAttrName(attrName);
attrKeyService.update(attrKey);
return Rets.success();
}
}
package cn.enilu.flash.api.controller.shop;
import cn.enilu.flash.bean.core.BussinessLog;
import cn.enilu.flash.bean.entity.shop.AttrKey;
import cn.enilu.flash.bean.entity.shop.AttrVal;
import cn.enilu.flash.bean.exception.ApplicationException;
import cn.enilu.flash.bean.exception.ApplicationExceptionEnum;
import cn.enilu.flash.bean.vo.front.Rets;
import cn.enilu.flash.bean.vo.query.SearchFilter;
import cn.enilu.flash.service.shop.AttrKeyService;
import cn.enilu.flash.service.shop.AttrValService;
import cn.enilu.flash.utils.Lists;
import cn.enilu.flash.utils.Maps;
import cn.enilu.flash.utils.StringUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import java.util.List;
@RestController
@RequestMapping("/shop/attr/val")
public class AttrValController {
private Logger logger = LoggerFactory.getLogger(getClass());
@Autowired
private AttrValService attrValService;
@Autowired
private AttrKeyService attrKeyService;
@RequestMapping(value = "/getAttrByCategoryAndGoods/{idCategory}",method = RequestMethod.GET)
public Object getAttrByCategoryAndGoods(@PathVariable("idCategory") Long idCategory) {
List<AttrKey> keyList = attrKeyService.queryBy(idCategory);
List<Long> idAttrKeyList = Lists.newArrayList();
for(AttrKey attrKey:keyList){
idAttrKeyList.add(attrKey.getId());
}
List<AttrVal> valList = Lists.newArrayList();
if(!idAttrKeyList.isEmpty()) {
valList = attrValService.queryAll(SearchFilter.build("idAttrKey", SearchFilter.Operator.IN, idAttrKeyList));
}
return Rets.success(Maps.newHashMap(
"keyList", keyList,
"valList", valList
));
}
@RequestMapping(value = "getAttrVals", method = RequestMethod.GET)
public Object getAttrVals(@RequestParam("idAttrKey")Long idAttrKey) {
List<AttrVal> list = attrValService.queryAll(SearchFilter.build("idAttrKey",idAttrKey));
return Rets.success(list);
}
@RequestMapping(method = RequestMethod.POST)
@BussinessLog(value = "编辑商品属性值", key = "attrVal")
public Object save(@RequestParam("idAttrKey")Long idAttrKey,
@RequestParam(value = "id",required = false)Long id,
@RequestParam("attrVal")String attrVal) {
AttrVal entity = new AttrVal();
if(id!=null){
entity = attrValService.get(id);
}
entity = attrValService.get(Lists.newArrayList(
SearchFilter.build("idAttrKey",idAttrKey),
SearchFilter.build("attrVal",attrVal)
));
if (id == null) {
if(entity==null) {
entity = new AttrVal();
entity.setIdAttrKey(idAttrKey);
entity.setAttrVal(attrVal);
attrValService.insert(entity);
}else{
return Rets.failure("不能添加重复的规格");
}
} else {
if(entity!=null){
return Rets.failure("不能添加重复的规格");
}else {
entity = new AttrVal();
entity.setIdAttrKey(idAttrKey);
entity.setAttrVal(attrVal);
attrValService.update(entity);
}
}
return Rets.success();
}
@RequestMapping(method = RequestMethod.DELETE)
@BussinessLog(value = "删除商品属性值", key = "id")
public Object remove(Long id) {
if (StringUtil.isEmpty(id)) {
throw new ApplicationException(ApplicationExceptionEnum.REQUEST_NULL);
}
attrValService.deleteById(id);
return Rets.success();
}
@RequestMapping(value="updateAttrVal",method = RequestMethod.POST)
@BussinessLog(value = "修改商品属性值", key = "id")
public Object updateAttrName(@RequestParam("id") Long id,@RequestParam("attrVal") String attrVal){
if (StringUtil.isEmpty(id)) {
throw new ApplicationException(ApplicationExceptionEnum.REQUEST_NULL);
}
AttrVal attrValEntity = attrValService.get(id);
attrValEntity.setAttrVal(attrVal);
attrValService.update(attrValEntity);
return Rets.success();
}
}
package cn.enilu.flash.api.controller.shop;
import cn.enilu.flash.bean.constant.factory.PageFactory;
import cn.enilu.flash.bean.entity.shop.Cart;
import cn.enilu.flash.bean.vo.front.Rets;
import cn.enilu.flash.service.shop.CartService;
import cn.enilu.flash.utils.factory.Page;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
@RestController
@RequestMapping("/shop/cart")
public class CartController {
private Logger logger = LoggerFactory.getLogger(getClass());
@Autowired
private CartService cartService;
@RequestMapping(value = "/list",method = RequestMethod.GET)
public Object list() {
Page<Cart> page = new PageFactory<Cart>().defaultPage();
page = cartService.queryPage(page);
return Rets.success(page);
}
}
package cn.enilu.flash.api.controller.shop;
import cn.enilu.flash.bean.constant.factory.PageFactory;
import cn.enilu.flash.bean.core.BussinessLog;
import cn.enilu.flash.bean.entity.cms.Banner;
import cn.enilu.flash.bean.entity.shop.AttrKey;
import cn.enilu.flash.bean.entity.shop.Category;
import cn.enilu.flash.bean.entity.shop.CategoryBannerRel;
import cn.enilu.flash.bean.enumeration.Permission;
import cn.enilu.flash.bean.exception.ApplicationException;
import cn.enilu.flash.bean.exception.ApplicationExceptionEnum;
import cn.enilu.flash.bean.vo.front.Rets;
import cn.enilu.flash.bean.vo.query.SearchFilter;
import cn.enilu.flash.service.shop.AttrKeyService;
import cn.enilu.flash.service.shop.CategoryBannerRelService;
import cn.enilu.flash.service.shop.CategoryService;
import cn.enilu.flash.service.shop.GoodsService;
import cn.enilu.flash.utils.Lists;
import cn.enilu.flash.utils.factory.Page;
import cn.enilu.flash.web.controller.BaseController;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import java.util.List;
@RestController
@RequestMapping("/shop/category")
public class CategoryController extends BaseController {
private Logger logger = LoggerFactory.getLogger(getClass());
@Autowired
private CategoryService categoryService;
@Autowired
private CategoryBannerRelService categoryBannerRelService;
@Autowired
private AttrKeyService attrKeyService;
@Autowired
private GoodsService goodsService;
@RequestMapping(value = "/list",method = RequestMethod.GET)
public Object list() {
Page<Category> page = new PageFactory<Category>().defaultPage();
page = categoryService.queryPage(page);
return Rets.success(page);
}
@RequestMapping(value = "/getAll",method = RequestMethod.GET)
public Object getAll() {
List<Category> categories = categoryService.queryAll();
return Rets.success(categories);
}
@RequestMapping(method = RequestMethod.POST)
@BussinessLog(value = "编辑商品类别", key = "name")
@RequiresPermissions(value = {Permission.CATEGORY_EDIT})
public Object save(@ModelAttribute Category category){
if(category.getId()==null){
categoryService.insert(category);
}else {
categoryService.update(category);
}
return Rets.success();
}
@RequestMapping(method = RequestMethod.DELETE)
@BussinessLog(value = "删除商品类别", key = "id")
@RequiresPermissions(value = {Permission.CATEGORY_EDIT})
public Object remove(Long id){
if (id == null) {
throw new ApplicationException(ApplicationExceptionEnum.REQUEST_NULL);
}
long goodsCount = goodsService.count(SearchFilter.build("idCategory",id));
if(goodsCount>0){
throw new ApplicationException(ApplicationExceptionEnum.DATA_CANNOT_REMOVE);
}
categoryService.deleteById(id);
return Rets.success();
}
@RequestMapping(value="/getBanners/{idCategory}",method = RequestMethod.GET)
public Object getBanners(@PathVariable("idCategory") Long idCategory){
if (idCategory == null) {
throw new ApplicationException(ApplicationExceptionEnum.REQUEST_NULL);
}
List<CategoryBannerRel> relList = categoryBannerRelService.queryAll(SearchFilter.build("idCategory", SearchFilter.Operator.EQ,idCategory));
List<Banner> bannerList = Lists.newArrayList();
relList.forEach( item->{
bannerList.add(item.getBanner());
});
return Rets.success(bannerList);
}
@RequestMapping(value ="getAttrKeys/{idCategory}",method = RequestMethod.GET)
public Object getAttrKeys(@PathVariable("idCategory") Long idCategory){
if (idCategory == null) {
throw new ApplicationException(ApplicationExceptionEnum.REQUEST_NULL);
}
List<AttrKey> list = attrKeyService.queryBy(idCategory);
return Rets.success(list);
}
@RequestMapping(value="/removeBanner/{idCategory}/{idBanner}",method = RequestMethod.DELETE)
@RequiresPermissions(value = {Permission.CATEGORY_EDIT})
public Object removeBanner(@PathVariable("idCategory") Long idCategory,
@PathVariable("idBanner") Long idBanner){
if (idCategory == null) {
throw new ApplicationException(ApplicationExceptionEnum.REQUEST_NULL);
}
CategoryBannerRel rel = categoryBannerRelService.get(Lists.newArrayList(
SearchFilter.build("idCategory",idCategory),
SearchFilter.build("idBanner",idBanner)
));
if(rel!=null){
categoryBannerRelService.delete(rel);
}
return Rets.success();
}
@RequestMapping(value="/setBanner/{idCategory}/{idBanner}",method = RequestMethod.POST)
@RequiresPermissions(value = {Permission.CATEGORY_EDIT})
public Object setBanner(@PathVariable("idCategory") Long idCategory,
@PathVariable("idBanner") Long idBanner){
if (idCategory == null) {
throw new ApplicationException(ApplicationExceptionEnum.REQUEST_NULL);
}
CategoryBannerRel rel = categoryBannerRelService.get(Lists.newArrayList(
SearchFilter.build("idCategory",idCategory),
SearchFilter.build("idBanner",idBanner)
));
if(rel!=null){
return Rets.success();
}
rel = new CategoryBannerRel();
rel.setIdCategory(idCategory);
rel.setIdBanner(idBanner);
categoryBannerRelService.insert(rel);
return Rets.success();
}
}
package cn.enilu.flash.api.controller.shop;
import cn.enilu.flash.bean.constant.factory.PageFactory;
import cn.enilu.flash.bean.entity.shop.Favorite;
import cn.enilu.flash.bean.vo.front.Rets;
import cn.enilu.flash.service.shop.FavoriteService;
import cn.enilu.flash.utils.factory.Page;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
@RestController
@RequestMapping("/shop/favorite")
public class FavoriteController {
private Logger logger = LoggerFactory.getLogger(getClass());
@Autowired
private FavoriteService favoriteService;
@RequestMapping(value = "/list",method = RequestMethod.GET)
public Object list() {
Page<Favorite> page = new PageFactory<Favorite>().defaultPage();
page = favoriteService.queryPage(page);
return Rets.success(page);
}
}
This diff could not be displayed because it is too large.
No preview for this file type
This diff could not be displayed because it is too large.
This diff could not be displayed because it is too large.
No preview for this file type
No preview for this file type
This diff could not be displayed because it is too large.
This diff could not be displayed because it is too large.
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!