Skip to content

Commit

Permalink
2
Browse files Browse the repository at this point in the history
  • Loading branch information
whh1009 committed Apr 26, 2016
1 parent b72964e commit def208e
Show file tree
Hide file tree
Showing 13 changed files with 623 additions and 259 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
*.classpath
cw/.classpath
15 changes: 15 additions & 0 deletions cw/.classpath
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,20 @@
<attribute name="owner.project.facets" value="jst.web.jstl"/>
</attributes>
</classpathentry>
<classpathentry kind="lib" path="WebRoot/WEB-INF/lib/activation-1.1.1.jar"/>
<classpathentry kind="lib" path="WebRoot/WEB-INF/lib/commons-codec-1.10.jar"/>
<classpathentry kind="lib" path="WebRoot/WEB-INF/lib/commons-lang3-3.4.jar"/>
<classpathentry kind="lib" path="WebRoot/WEB-INF/lib/commons-logging-1.2.jar"/>
<classpathentry kind="lib" path="WebRoot/WEB-INF/lib/cos-26Dec2008.jar"/>
<classpathentry kind="lib" path="WebRoot/WEB-INF/lib/druid-0.2.15.jar"/>
<classpathentry kind="lib" path="WebRoot/WEB-INF/lib/gimap-1.5.1.jar"/>
<classpathentry kind="lib" path="WebRoot/WEB-INF/lib/jfinal-2.0-bin-with-src.jar"/>
<classpathentry kind="lib" path="WebRoot/WEB-INF/lib/jsoup-1.8.3.jar"/>
<classpathentry kind="lib" path="WebRoot/WEB-INF/lib/log4j-1.2.16.jar"/>
<classpathentry kind="lib" path="WebRoot/WEB-INF/lib/mysql-connector-java-5.1.20-bin.jar"/>
<classpathentry kind="lib" path="WebRoot/WEB-INF/lib/poi-3.13-20150929.jar"/>
<classpathentry kind="lib" path="WebRoot/WEB-INF/lib/poi-ooxml-3.13-20150929.jar"/>
<classpathentry kind="lib" path="WebRoot/WEB-INF/lib/poi-ooxml-schemas-3.13-20150929.jar"/>
<classpathentry kind="lib" path="WebRoot/WEB-INF/lib/xmlbeans-2.3.0.jar"/>
<classpathentry kind="output" path="WebRoot/WEB-INF/classes"/>
</classpath>
22 changes: 11 additions & 11 deletions cw/WebRoot/cw/BookList.jsp
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.

<body>
<jsp:include page="_header.jsp"></jsp:include>
<div class="container-fluid">
<div class="container">
<div class="row">
<div class="col-sm-8">
<select id="excelSel" class="form-control">
Expand Down Expand Up @@ -139,7 +139,7 @@ String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.
mySearchSql = "1=1";
getSearchCondition();
_page = page;
$.post("${ctx}/getBookList", {mySearchSql:mySearchSql, page:_page}, function(data) {
$.post("${ctx}/book/getBookList", {mySearchSql:mySearchSql, page:_page}, function(data) {
var content="";
if(data&&data.list.length) {
for(var i = 0; i < data.list.length; i++) {
Expand All @@ -149,13 +149,13 @@ String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.
content+="<td>"+data.list[i].book_name+"</td>";
content+="<td>"+data.list[i].book_lang+"</td>";
content+="<td>"+data.list[i].book_author+"</td>";
content+="<td>"+data.list[i].epub_price+"</td>";
content+="<td>"+data.list[i].pdf_price+"</td>";
content+="<td>"+data.list[i].ad_price+"</td>";
content+="<td>"+(data.list[i].epub_price+data.list[i].pdf_price+data.list[i].ad_price)+"</td>";
content+="<td>"+data.list[i].author_royalty+"</td>";
content+="<td>"+data.list[i].epub_price.toFixed(2)+"</td>";
content+="<td>"+data.list[i].pdf_price.toFixed(2)+"</td>";
content+="<td>"+data.list[i].ad_price.toFixed(2)+"</td>";
content+="<td>"+(data.list[i].epub_price+data.list[i].pdf_price+data.list[i].ad_price).toFixed(2)+"</td>";
content+="<td>"+data.list[i].author_royalty.toFixed(2)+"</td>";
content+="<td>"+data.list[i].trans_time+"</td>";
content+="<td><a href=\"${ctx}/bookInfo?id="+data.list[i].id+"\" title='修改'><span class='glyphicon glyphicon-pencil' style='color:blue'></span></a>&nbsp;&nbsp;&nbsp;<a href=\"javascript:updateBook('"+data.list[i].id+"')\" title='删除'><span class='glyphicon glyphicon-trash' style='color:red'></span></a></td>";
content+="<td><a href=\"${ctx}/book/bookInfo?id="+data.list[i].id+"\" title='修改'><span class='glyphicon glyphicon-pencil' style='color:blue'></span></a>&nbsp;&nbsp;&nbsp;<a href=\"javascript:updateBook('"+data.list[i].id+"')\" title='删除'><span class='glyphicon glyphicon-trash' style='color:red'></span></a></td>";
content+="</tr>";
}
initPage(data.pageNumber, data.totalPage, data.totalRow);
Expand All @@ -168,7 +168,7 @@ String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.
//初始化批次映射
function initExcelMap() {
$.ajax({
url:"${ctx}/getExcelList",
url:"${ctx}/book/getExcelList",
method:"POST",
beforeSend:function() {
$("#excelSel").html("<option value='0'>暂无数据</option>");
Expand Down Expand Up @@ -236,7 +236,7 @@ String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.
//总结统计
function getSummary() {
$.ajax({
url:"${ctx}/getSummary",
url:"${ctx}/book/getSummary",
data:{mySearchSql:mySearchSql},
method:"POST",
success:function(data) {
Expand Down Expand Up @@ -308,7 +308,7 @@ String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.
//
function updateBook(bId) {
if(confirm("确定要删除吗?")) {
$.post("${ctx}/updateBookById", {bookId:bId}, function(data) {
$.post("${ctx}/book/updateBookById", {bookId:bId}, function(data) {
if(data=="1") {
alert("删除成功");
initSearch(_page);
Expand Down
4 changes: 2 additions & 2 deletions cw/WebRoot/cw/ImportBookBase.jsp
Original file line number Diff line number Diff line change
Expand Up @@ -38,14 +38,14 @@
$("#file").fileinput({
language: "zh",
uploadUrl: "${ctx }/uploadBaseBookExcel",
uploadUrl: "${ctx }/import/uploadBaseBookExcel",
maxFilesNum: 1,
allowedFileExtensions : ["xlsx"],
});
$(function() {
$("#file").on("fileuploaded", function(event, data, previewId, index) {
$.ajax({
url:"${ctx }/saveBaseBookExcel",
url:"${ctx }/import/saveBaseBookExcel",
type:"post",
dataType:"json",
beforeSend: function () {
Expand Down
8 changes: 4 additions & 4 deletions cw/WebRoot/cw/_header.jsp
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ $(function() {
</script>
<!-- http://work.smarchal.com/twbscolor/css/e74c3cc0392becf0f1ffbbbc0 -->
<nav class="navbar navbar-default" role="navigation">
<!-- <div class="container"> -->
<div class="container">
<!-- Brand and toggle get grouped for better mobile display -->
<div class="navbar-header">
<button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#bs-example-navbar-collapse-1" aria-expanded="false">
Expand All @@ -125,12 +125,12 @@ $(function() {
<li class="active"><a href="${ctx }/">首页 <span class="sr-only">(current)</span></a></li>
<li class="dropdown"><a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="false">数据导入 <span class="caret"></span></a>
<ul class="dropdown-menu">
<li><a href="${ctx }/importBaseBookPage"><i class='glyphicon glyphicon-import'></i>&nbsp;图书基本信息导入</a></li>
<li><a href="${ctx }/import/importBaseBookPage"><i class='glyphicon glyphicon-import'></i>&nbsp;图书基本信息导入</a></li>
<li><a href="${ctx }/importBaseBookPage"><i class='glyphicon glyphicon-import'></i>&nbsp;亚马逊(中国)导入</a></li>
<li><a href="${ctx }/importBaseBookPage"><i class='glyphicon glyphicon-import'></i>&nbsp;亚马逊(美国)导入</a></li>
</ul>
</li>
<li><a href="${ctx }/bookList"><i class='glyphicon glyphicon-tasks'></i>&nbsp;图书列表</a></li>
<li><a href="${ctx }/book/bookList"><i class='glyphicon glyphicon-tasks'></i>&nbsp;图书列表</a></li>
<%-- <li><a href="${ctx }/importBaseBookPage">图书基本信息导入</a></li> --%>
</ul>
<!--
Expand All @@ -150,6 +150,6 @@ $(function() {

</div>
<!-- /.navbar-collapse -->
<!-- </div> -->
</div>
<!-- /.container-fluid -->
</nav>
2 changes: 2 additions & 0 deletions cw/src/com/wuzhou/config/WZConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import com.jfinal.plugin.activerecord.ActiveRecordPlugin;
import com.jfinal.render.ViewType;
import com.mysql.jdbc.jdbc2.optional.MysqlDataSource;
import com.wuzhou.controller.BookController;
import com.wuzhou.controller.ExcelImportController;
import com.wuzhou.controller.IndexController;
import com.wuzhou.controller.UserController;
Expand All @@ -37,6 +38,7 @@ public void configRoute(Routes me) {
me.add("/", IndexController.class);
me.add("/import", ExcelImportController.class);
me.add("/user", UserController.class);
me.add("/book", BookController.class);
}

@Override
Expand Down
150 changes: 150 additions & 0 deletions cw/src/com/wuzhou/controller/BookController.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,150 @@
package com.wuzhou.controller;

import org.apache.log4j.Logger;

import com.jfinal.aop.Enhancer;
import com.jfinal.core.Controller;
import com.jfinal.kit.JsonKit;
import com.wuzhou.bean.BookBaseBean;
import com.wuzhou.service.BookService;
import com.wuzhou.service.ExcelMapService;
import com.wuzhou.service.UserService;

/**
*
* @author wanghonghui
*
*/
public class BookController extends Controller {
Logger log = Logger.getLogger(BookController.class);
UserService userService = Enhancer.enhance(UserService.class);
BookService service = Enhancer.enhance(BookService.class);
ExcelMapService excelMapService = Enhancer.enhance(ExcelMapService.class);
/**
* 书号检索列表页面
*/
public void bookList() {
setAttr("searchConditionJson", JsonKit.toJson(BookBaseBean.getInstence().searchConditionMap));
render("/cw/BookList.jsp");
}

public void bookInfo() {
int id = getParaToInt("id", 0);
if(id==0) {
setAttr("bookBaseModel", "");
} else {
try{
setAttr("bookBaseModel", service.getBookInfo(id));
} catch(Exception ex) {
setAttr("bookBaseModel", "");
ex.printStackTrace();
log.error(ex);
}
}
render("/cw/EditBook.jsp");
}

/**
* 书号列表
*/
public void getBookList() {
String mySearchSql = getPara("mySearchSql", "1=1");
int pageNumber = getParaToInt("page", 1);
try {
renderJson(service.getBookList(pageNumber, mySearchSql, 1));
} catch(Exception ex) {
renderJson("-1");
ex.printStackTrace();
log.error(ex);
}
}

public void getSummary() {
String mySearchSql = getPara("mySearchSql", "1=1");
try {
renderJson(service.getSummary(mySearchSql));
} catch(Exception ex) {
renderJson("-1");
ex.printStackTrace();
log.error(ex);
}
}

public void getExcelList() {
renderJson(excelMapService.getExcelList());
}

/**
* 被“删除”的图书
*/
public void bookDelPage() {
setAttr("userJson", JsonKit.toJson(userService.getUserList()));
render("/cw/DelBookList.jsp");
}

/**
* 假删除图书
*/
public void updateBookById() {
int bookId = getParaToInt("bookId", 0);
if(bookId==0) {
renderJson("0");
return;
}
try {
if(service.updateBookById(bookId, 0)) {
renderJson("1");
} else {
renderJson("2");
}
} catch(Exception ex) {
renderJson("-1");
ex.printStackTrace();
log.error(ex);
}
}

/**
* 恢复图书
*/
public void recoveryBookById() {
// int bookId = getParaToInt("bookId", 0);
// if(bookId==0) {
// renderJson("0");
// return;
// }
// try {
// if(service.updateBookById(bookId, 1)) {
// renderJson("1");
// } else {
// renderJson("2");
// }
// } catch(Exception ex) {
// renderJson("-1");
// ex.printStackTrace();
// log.error(ex);
// }
}

/**
* 删除图书
*/
public void deleteBookById() {
int bookId = getParaToInt("bookId", 0);
if(bookId==0) {
renderJson("0");
return;
}
try {
if(service.deleteBookById(bookId)) {
renderJson("1");
} else {
renderJson("2");
}
} catch(Exception ex) {
renderJson("-1");
ex.printStackTrace();
log.error(ex);
}
}
}
66 changes: 64 additions & 2 deletions cw/src/com/wuzhou/controller/ExcelImportController.java
Original file line number Diff line number Diff line change
@@ -1,18 +1,80 @@
package com.wuzhou.controller;

import java.io.File;
import java.util.Date;

import org.apache.log4j.Logger;

import com.jfinal.aop.Enhancer;
import com.jfinal.core.Controller;
import com.jfinal.kit.PathKit;
import com.jfinal.upload.UploadFile;
import com.wuzhou.Result;
import com.wuzhou.service.ExcelImportService;
import com.wuzhou.service.ExcelMapService;
import com.wuzhou.service.UserService;

/**
* excel导入控制
* @author wanghonghui
*
*/
public class ExcelImportController extends Controller{
Logger log = Logger.getLogger(ExcelImportController.class);

UserService userService = Enhancer.enhance(UserService.class);
ExcelMapService excelMapService = Enhancer.enhance(ExcelMapService.class);
ExcelImportService service = Enhancer.enhance(ExcelImportService.class);

Result result = new Result();

/**
* 图书基本信息导入页面
*/
public void baseBookImportPage() {
render("");
public void importBaseBookPage() {
render("/cw/ImportBookBase.jsp");
}

/**
* 上传excel
*/
public void uploadBaseBookExcel() {
UploadFile file = getFile("file");
String uploadExcelName = file.getOriginalFileName();
String serverExcelName = new Date().getTime()+".xlsx";
String filePath = PathKit.getWebRootPath()+File.separator+"uploadFiles"+File.separator+serverExcelName;
file.getFile().renameTo(new File(filePath));
try{
excelMapService.addExcelMap(uploadExcelName, serverExcelName);
setSessionAttr("excelPath", filePath);
renderJson("0");
} catch(Exception ex) {
ex.printStackTrace();
renderJson(ex.getMessage());
log.error(ex);
}
}

/**
* 解析excel并返回
*/
public void saveBaseBookExcel() {
Object excelPath = getSessionAttr("excelPath");
if(excelPath==null) {
result.setStatus(false);
result.setMessage("未加载到EXCEL");
return;
}
try{
int out = service.parserBookBaseExcel(excelPath.toString());
result.setStatus(true);
result.setMessage("共入库["+out+"]本");
} catch(Exception ex) {
ex.printStackTrace();
result.setStatus(false);
result.setMessage(ex.getMessage());
log.error(ex);
}
renderJson(result);
}
}
Loading

0 comments on commit def208e

Please sign in to comment.